EF can you make a Mutli-column Index using shadow properties?

后端 未结 1 1050
离开以前
离开以前 2021-01-18 05:36

I\'m trying to create a multi-column unique index using a shadow property. I know I can solve this problem with just adding a property, but I would like to see if this is po

相关标签:
1条回答
  • 2021-01-18 06:05

    It's possible. You can simply use the HasIndex overload with params string[] propertyNames.

    First make sure the shadow property is defined:

    modelBuilder.Entity<AlbumTrack>()
        .Property<int>("AlbumId");
    

    and then define the index:

    modelBuilder.Entity<AlbumTrack>()
        .HasIndex("TrackNumber", "AlbumId")
        .IsUnique();
    
    0 讨论(0)
提交回复
热议问题