首页 > 解决方案 > 在 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 部分提供解决方案,说明如何做同样的事情。

标签: c#entity-framework-coreentity-framework-6roslynasp.net-core-3.1

解决方案


推荐阅读