Add index with entity framework code first (CTP5)

前端 未结 4 1909
走了就别回头了
走了就别回头了 2020-12-13 01:02

Is there a way to get EF CTP5 to create an index when it creates a schema?

Update: See here for how EF 6.1 handles this (as pointed out by juFo belo

4条回答
  •  我在风中等你
    2020-12-13 01:08

    This feature should be available in the near-future via data annotations and the Fluent API. Microsoft have added it into their public backlog:

    http://entityframework.codeplex.com/workitem/list/basic?keywords=DevDiv [Id=87553]

    Until then, you'll need to use a seed method on a custom Initializer class to execute the SQL to create the unique index, and if you're using code-first migrations, create a new migration for adding the unique index, and use the CreateIndex and DropIndex methods in your Up and Down methods for the migration to create and drop the index.

提交回复
热议问题