Entity Framework Code First Fluent Api: Adding Indexes to columns

前端 未结 15 1364
一生所求
一生所求 2020-11-30 17:43

I\'m running EF 4.2 CF and want to create indexes on certain columns in my POCO objects.

As an example lets say we have this employee class:

public c         


        
15条回答
  •  爱一瞬间的悲伤
    2020-11-30 18:11

    For anyone using Entity Framework 6.1+, you can do the following with fluent api:

    modelBuilder 
        .Entity() 
        .Property(t => t.Name) 
        .HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute()));
    

    Read more in the documentation.

提交回复
热议问题