Indices with SchemaBuilder

Topics: Writing modules
Developer
Sep 28, 2011 at 12:18 PM

Hi all!

Is there a way to declare indices on columns in a migration class with SchemaBuilder? It seems that there is no such option. Does that mean that if I query for a specific column (which is not the primary key) SQL Server makes a full table scan?

Sep 28, 2011 at 3:41 PM
Edited Sep 28, 2011 at 3:47 PM

You can actually define an Index with SchemaBuilder using AlterTable method, ie:

SchemaBuilder.CreateTable("BlogPartArchiveRecord",
table => table
  .Column<int>("Id", column => column.PrimaryKey().Identity())
  .Column<int>("Year")
  .Column<int>("Month")
  .Column<int>("PostCount")
  .Column<int>("BlogPart_id")
).AlterTable("BlogPartArchiveRecord",
table => table
.CreateIndex("MyIndexName""Year""Month")
);

Method signature:
AlterTableCommand.CreateIndex(string indexName, params string[] columnNames);
Developer
Sep 29, 2011 at 7:47 AM

Thank you a lot, I didn't looked in AlterTable...