Asp.net Core Entity Framework cannot find IndexAttribute

后端 未结 2 1478
醉话见心
醉话见心 2021-02-05 12:32

I receive the following from Visual Studio Code on my Mac, both in IDE and console window after executing \"dotnet run\":

The type or namespace name \'IndexAttribute\' c

2条回答
  •  鱼传尺愫
    2021-02-05 12:48

    This seems to have changed since you asked the question. jsakamoto has implemented NuGet package that allows you to keep your [Index] attribute. The only difference is order of variables; you can no longer have Order=0 as your last variable but rather do:

    [Index("IX_TreeFiddy", 0, IsUnique = false)]
    public string LochNessMonster { get; set; }
    
    [Index("IX_TreeFiddy", 1, IsUnique = false)]
    public int CentsGiven { get; set; }
    

    Override OnModelCreating()

    // Override "OnModelCreating"
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
    
        // .. and invoke "BuildIndexesFromAnnotations"!
        modelBuilder.BuildIndexesFromAnnotations();
    }
    

    Here is link to: IndexAttribute for .NET Core NuGet package

提交回复
热议问题