c# - 在 EF Core 3.1 中替换 HasColumnAnnotation() 的最佳方法是什么
问题描述
我已经将EntityFramework 6的项目实现到EntityFramework Core 3.1中。在 EF6 中,我们使用 HasColumnAnnotation() 方法在模型中为用于存储属性的数据库列设置注释。
示例.cs
private void CreateCompositeUnique(DbModelBuilder modelBuilder,
string indexName)
{
modelBuilder
.Entity<Web>()
.Property(x=>x.Url)
.HasColumnAnnotation(IndexAnnotation.AnnotationName,
new IndexAnnotation(new IndexAttribute(indexName) { IsUnique = true }));
}
在我的模式定义中重构许多 HasColumnAnnotation 和 IndexAnnotation 用法->链接建议 HasIndex() 方法。但仍然混淆它是否正确?
而且我还必须使用 Roslyn API 将 HasColumnAnnotation() 迁移到 HasIndex() 中。
请澄清转型并为 Roslyn 部分提供解决方案,说明如何做同样的事情。
解决方案
推荐阅读
- git - 有没有 GItHub 网络图的 api
- sql - 如何根据来自同一个表的唯一值加入两次在 postgres 中创建数组?
- javascript - Mongoose - CastError Cast to string failed for value "Object"
- c# - 在 C# winForm 中使用数据字典匹配列
- azure-ad-b2c - 如何在不注入 B2C 生成的表单控件的情况下自定义 Azure B2C 模板
- yugabyte-db - 在 YugabyteDB YSQL 中分片时如何对列进行哈希处理
- kotlin - 从两个可变集合检查不重叠的元素 - kotlin
- javascript - Dropzone 正在为每个文件删除/选择将所有文件上传到服务器
- c# - 在特定环境(本地主机)中禁用 HangFire 服务器
- laravel - 如何在 Laravel 中为单个输入添加“EXIST”和“IN”验证