How to create index in Entity Framework 6.2 with code first

前端 未结 10 485
不知归路
不知归路 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:41

    If you don't want to use attributes on your POCO's, then you can always do it like the following:

    context.Database.ExecuteSqlCommand("CREATE INDEX IX_NAME ON ..."); 
    

    You can execute this statement in your custom DbInitializer derived class. I don't know any Fluent API way of doing this though.

提交回复
热议问题