现在,实体框架6.1的最新测试版中提供了索引,是否可以在代码优先方法中创建一个等于此SQL语句的索引?
CREATE NONCLUSTERED INDEX [Sample1]
ON [dbo].[Logs] ([SampleId],[Date])
INCLUDE ([Value])
答案 0 :(得分:36)
严格来说,在Code First Migrations中始终可以使用它,因为您可以在迁移中运行sql:
public partial class AddIndexes : DbMigration
{
private const string IndexName = "IX_LogSamples";
public override void Up()
{
Sql(String.Format(@"CREATE NONCLUSTERED INDEX [{0}]
ON [dbo].[Logs] ([SampleId],[Date])
INCLUDE ([Value])", IndexName));
}
public override void Down()
{
DropIndex("dbo.Logs", IndexName);
}
}
但我意识到你可能真的在问你是否可以在6.1中引入create an index using the IndexAttribute,但是在Include专栏中 - 答案是“否”