Devart.Data.Oracle.Entity.EFCore can not but index at the same schema as the table
Posted: Thu 14 Nov 2019 18:04
Hey, I'm having an issue using EFCore Migrations. I have a table under an specific schema, and I'm creating an index for some column of this table. When I generate the migration script, the script does not put the index in the same schema as the table.
From instance, this entity configuration:
It will generate the following create index in the migration file:
And the create index statment in the script will be this:
Now, If I perform this migration connected with the AllFather user, the index owner ends up being the AllFather schema, with the table owner being the SomeSchema. This becuase the create index statment does not provide the schema owner of the index.
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.
It contains a Schema property, but it is used as the table schema, not the index schema.
The summary of the property says to following:
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:
This would generate the following migration script:
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)