From instance, this entity configuration:
Code: Select all
modelBuilder.Entity<Setting>(b =>
{
b.ToTable("Settings", "SomeSchema");
b.HasKey(s => s.Id);
b.HasIndex(s => s.Key);
});
Code: Select all
migrationBuilder.CreateIndex(
name: "IX_Settings_Key",
schema: "SomeSchema",
table: "Settings",
column: "Key");
Code: Select all
CREATE INDEX IX_Settings_Key ON SomeSchema.Settings (Key)
When I was creating the index I was expecting the index to be placed at the same schema as the table.
Looking at the CreateIndexOperation class.
Code: Select all
public class CreateIndexOperation : MigrationOperation
{
public CreateIndexOperation();
public virtual bool IsUnique { get; set; }
public virtual string Name { get; set; }
public virtual string Schema { get; set; }
public virtual string Table { get; set; }
public virtual string[] Columns { get; set; }
public virtual string Filter { get; set; }
}
The summary of the property says to following:
I understand that changing the purpose of the property would probably cause a breaking change.The schema that contains the index, or null if the default schema should be used.
But it would be nice if you could put some extension on the IndexBuilder class, that added one annotation to inform the index schema. This annotation, if present, would be used to build the create index statement.
Something like this:
Code: Select all
b.HasIndex(s => s.Key)
.HasSchema("SomeSchema")
Code: Select all
CREATE INDEX SomeSchema.IX_Settings_Key ON SomeSchema.Settings (Key)