Well, the problem is now resolved. I am currently working with DbConnections.
public MyContext() : base(ConnectionManager.Connection, true) { Database.SetInitializer<MyContext>(new MyContextInitializer()); Configuration.ProxyCreationEnabled = false; } public MyContext(DbConnection connection) : base(connection, true) { Database.SetInitializer<MyContext>(new MyContextInitializer()); Configuration.ProxyCreationEnabled = false; }
I am creating a DbConnection in a special class, I think it would be impractical to post the code here. But basically this is something like this:
DbConnection conn = null; switch (Type) { case ConnectionType.LocalDB: conn = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateConnection(); break; case ConnectionType.MySql: conn = DbProviderFactories.GetFactory("MySql.Data.MySqlClient").CreateConnection(); break; default: throw new System.InvalidOperationException(); } conn.ConnectionString = "Add provider specific connection string here";
Then you just need to give the code in context. In my case, I have a ConnectionManager, from where I read "defaul connection" when calling MyContext (), and there is a second Ctor that I call for "test connections".
source share