C# 替换EF Core 3.1中HasColumnAnnotation()的最佳方法是什么

C# 替换EF Core 3.1中HasColumnAnnotation()的最佳方法是什么,c#,entity-framework-core,entity-framework-6,roslyn,asp.net-core-3.1,C#,Entity Framework Core,Entity Framework 6,Roslyn,Asp.net Core 3.1,我已经将EntityFramework 6项目实施到EntityFramework Core 3.1中。在EF6中,我们使用HasColumnAnnotation()方法在模型中为用于存储属性的数据库列设置注释 Sample.cs private void CreateCompositeUnique(DbModelBuilder modelBuilder, string indexName) { modelBu

我已经将EntityFramework 6项目实施到EntityFramework Core 3.1中。在EF6中,我们使用HasColumnAnnotation()方法在模型中为用于存储属性的数据库列设置注释

Sample.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 }));
}
private void CreateCompositeUnique(DbModelBuilder modelBuilder,
字符串索引(名称)
{
建模者
.实体()
.Property(x=>x.Url)
.HasColumnAnnotation(IndexAnnotation.AnnotationName,
新的IndexAnnotation(新的IndexAttribute(indexName){IsUnique=true});
}
-->该链接建议使用HasIndex()方法。但仍不清楚它是否正确

我还必须使用Roslyn API将HasColumnAnnotation()迁移到HasIndex()


请澄清转换并为Roslyn部件提供解决方案,说明如何进行转换。

我相信您需要
.Property(x=>x.Url).HasIndex().IsUnique()
是的,它没有像您在Core 3.1中提到的那样工作,希望这样=>.HasIndex().IsUnique()。