In the free API, we can specify the index in the 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 get the CreateIndex statement:
CreateIndex("dbo.Employees", "EmployeeNumber", clustered: true, name: "IX_EmployeeNumber");
After a Update-Database , we have 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 a descendant stream? Something like:
CREATE CLUSTERED INDEX [IX_EmployeeNumber] ON [dbo].[Employees] ( [EmployeeNumber] DESC
I could not find the related parameters in CreateIndex . Is it possible to be achieved in the first code migration?
Of course, we know that we can get everything that works with DbMigration.Sql(...some sql statement...) . But how can we get the desired result using CreateIndex() ?
entity-framework ef-code-first code-first-migrations
Blaise
source share