In fluent API, we can specify an Index on a field:
var indexAttr = new IndexAttribute("IX_EmployeeNumber")
{
IsClustered = true
};
Property(c => c.EmployeeNumber)
.HasColumnAnnotation("Index", new IndexAnnotation(indexAttr ))
.HasMaxLength(8)
.IsRequired();
After Add-Migration, we will get this CreateIndex statement:
CreateIndex("dbo.Employees", "EmployeeNumber", clustered: true, name: "IX_EmployeeNumber");
After a Update-Database, we have a sql like this:
CREATE CLUSTERED INDEX [IX_EmployeeNumber] ON [dbo].[Employees]
(
[EmployeeNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
My question is: how can I create this index in descendent order? Something like:
CREATE CLUSTERED INDEX [IX_EmployeeNumber] ON [dbo].[Employees]
(
[EmployeeNumber] DESC
I couldn't find related parameters in CreateIndex. Is it possible to be achieved in Code First migration?
Of course we know we could get everything working with DbMigration.Sql(...some sql statement...). But, how can we obtain the desired result with CreateIndex()?