If you which to have contexts point to different Databases. then you should provide the
connection information and not use App.config ConnectionStrings.
YOUR content should have a constructor that allows CONNECTION info.
It can still have the old way there.
public abstract class YOURDbContext : DbContext, IContextOptions {
//ctors
protected YOURDbContext(string connectionName)
: base(connectionName) {
}
// YOU NEED THIS CONSTRUCTOR
protected YOURDbContext(DbConnection dbConnection, bool contextOwnsConnection)
: base(dbConnection, contextOwnsConnection) {
}
Each instance of thr context can be connected to a different database. You have more than 1 context at once.
you will need a Function PER database type to make sure the connectionInfo is constructured properly.
here is an Example get the DBConnection for SQLServer. Repeat for other providers.
public DbConnection GetSqlConn4DbName(string dataSource, string dbName) {
var sqlConnStringBuilder = new SqlConnectionStringBuilder();
sqlConnStringBuilder.DataSource = String.IsNullOrEmpty(dataSource) ? DefaultDataSource : dataSource;
sqlConnStringBuilder.IntegratedSecurity = true;
sqlConnStringBuilder.MultipleActiveResultSets = true;
var sqlConnFact = new SqlConnectionFactory(sqlConnStringBuilder.ConnectionString);
var sqlConn = sqlConnFact.CreateConnection(dbName);
return sqlConn;
}