6

I have a database that contains an unknown number of schemas, each schema has the exact same tables.

Is there anyway to change the schema at runtime when creating a new instance dbContext? I know it's possible to change connection strings at runtime, however the schema names is stored in another database as a table of configurations.

I saw that in EF6 you can set a defaultSchema when overriding OnModelCreating however I am not too sure if this is guaranteed to run everytime I use using (DatabaseContext db = new DatabaseContext()){}

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.HasDefaultSchema(SchemaName);
}
clifford.duke
  • 3,980
  • 10
  • 38
  • 63
  • Pretty sure you can't do it out of the box but this library can help: http://efmodeladapter.codeplex.com/ – DavidG Oct 21 '14 at 10:07
  • Have you seen http://stackoverflow.com/questions/2663164/changing-schema-name-on-runtime-entity-framework – artm Oct 21 '14 at 10:09

0 Answers0