Jadi, solusi akhirnya adalah:
-
Buat penerus DbConfiguration sendiri dengan blackjack dan pelacur:
public class MultipleDbConfiguration : DbConfiguration { #region Constructors public MultipleDbConfiguration() { SetProviderServices(MySqlProviderInvariantName.ProviderName, new MySqlProviderServices()); } #endregion Constructors #region Public methods public static DbConnection GetMySqlConnection(string connectionString) { var connectionFactory = new MySqlConnectionFactory(); return connectionFactory.CreateConnection(connectionString); } #endregion Public methods }
-
Tandai Ms_SqlContext dengan MultipleDbConfiguration (dan jangan lakukan apa pun dengan DbContext semacam itu)
[DbConfigurationType(typeof(MultipleDbConfiguration))] partial class Ms_SqlContext { }
-
Tandai Ms_SqlContext dengan MultipleDbConfiguration, dan sesuaikan MY_SqlContext(string nameOrConnectionString) dengan panggilan MultipleDbConfiguration.GetMySqlConnection(nameOrConnectionString)
[DbConfigurationType(typeof(MultipleDbConfiguration))] partial class MY_SqlContext : DbContext { public MY_SqlContext(string nameOrConnectionString) : base(MultipleDbConfiguration.GetMySqlConnection(nameOrConnectionString), true) {} }
-
ITULAH!!!