How to add an index on multiple columns with ASC/DESC sort using the Fluent API?

前端 未结 3 1320
梦如初夏
梦如初夏 2020-12-11 08:35

I have a MVC ASP.NET application using Entity Framework 6 - Code First approach.

Using the Fluent API, how can I add an index on multiple columns with ASC/DESC sor

3条回答
  •  误落风尘
    2020-12-11 09:18

    You can make it manually editing Migrations like this :

    public override void Up()
    {
        Sql("CREATE NONCLUSTERED INDEX [IX_Index_name] ON [dbo].[TableName] ([ColumnName1] Asc,[ColumnName2] Desc,[ColumnName3] Desc)");
    }
    
    public override void Down()
    {
         Sql("DROP INDEX [dbo].[TableName].[IX_Index_name]");
    }
    

提交回复
热议问题