You can implement the following convention:
public class DefaultSchemaConvention :
IConfigurationConvention<Type, EntityTypeConfiguration>
{
string defaultSchema;
public DefaultSchemaConvention(string defaultSchema)
{
if (String.IsNullOrWhiteSpace(defaultSchema))
throw new ArgumentException("defaultSchema");
this.defaultSchema = defaultSchema;
}
void IConfigurationConvention<Type, EntityTypeConfiguration>.Apply(
Type memberInfo, Func<EntityTypeConfiguration> configuration)
{
EntityTypeConfiguration cfg = configuration();
string tableName = cfg.EntitySetName;
if (String.IsNullOrEmpty(tableName))
tableName = memberInfo.Name;
cfg.ToTable(tableName, this.defaultSchema);
}
}
Usage:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.Edm.Db.ColumnTypeCasingConvention>();
modelBuilder.Conventions.Add(new DefaultSchemaConvention("TEST"));
}
There is a couple of side notes by Arthur Vickers here concerning TPT inheritance and many-to-many relations.
IConfigurationConvention
. – Amie