How to create index in Entity Framework 6.2 with code first

前端 未结 10 472
不知归路
不知归路 2020-11-29 19:16

Is there a way to create an index on a property/column using code-first, instead of using the new IndexAttribute ?

10条回答
  •  清酒与你
    2020-11-29 19:49

    You can use one of this

    // Indexes

     this.HasIndex(e => e.IsActive)
                .HasName("IX_IsActive");
    

    or

      this.Property(e => e.IsActive).HasColumnAnnotation(
                "Index",
                new IndexAnnotation(new IndexAttribute("IX_IsActive")));
    

提交回复
热议问题