11
实体框架在运行时更改连接
我有一个引用我的模型和DAL程序集的Web API项目。向用户显示一个登录屏幕,他可以在其中选择不同的数据库。 我建立连接字符串如下: public void Connect(Database database) { //Build an SQL connection string SqlConnectionStringBuilder sqlString = new SqlConnectionStringBuilder() { DataSource = database.Server, InitialCatalog = database.Catalog, UserID = database.Username, Password = database.Password, }; //Build an entity framework connection string EntityConnectionStringBuilder entityString = new EntityConnectionStringBuilder() { Provider = database.Provider, Metadata = Settings.Default.Metadata, …