Microsoft.EntityFrameworkCore 中的索引属性解决问题

Index Attribute resolving issue in Microsoft.EntityFrameworkCore

我有 .Net Standart 2.0 dll 来保持 MS SQL 服务器的分离实体。

Index Attribute 无法解析。

我已经搜索并尝试添加一些 Entity Framework 的命名空间,但即使 MSDN.

也没有任何效果

请帮忙。谢谢!

IndexAttribute Class

Specifies an index to be generated in the database.

Entity Framework Core

  • 5.0

您没有使用 EF core 5。您需要改用模型生成器


在此处阅读更多内容

Indexes

Configuring indexes via Data Annotations has been introduced in EF Core 5.0.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Blog>()
        .HasIndex(b => b.Url);
}