Entity Framework 6.1 - Create index with INCLUDE statement

后端 未结 1 1140
感情败类
感情败类 2020-12-29 01:59

So now that Indexes are available in latest beta version of Entity Framework 6.1 is it even possible to create an index in code first approach that is equal to this SQL stat

相关标签:
1条回答
  • 2020-12-29 02:45

    Strictly speaking it has been always possible in Code First Migrations because you can run sql in a migration:

       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);
            }
        }
    

    But I realise that you are probably actually asking if you can create an index using the IndexAttribute introduced in 6.1, but with an Include column - the answer to that is "No"

    0 讨论(0)
提交回复
热议问题