2
我得到了一個ADO.NET實體數據模型,我想在多個數據庫上使用(在同一臺服務器上),您將如何解決它?如何在實體框架連接上更改數據庫
// This results in a exception, "Specified method is not supported".
private MyEntities _db = new MyEntities();
public IQueryable<MyObject> GetMyObjects(string database)
{
_db.Connection.ChangeDatabase(database);
return _db.MyObjects
}
// This works...
private MyEntities _db;
private string entityConnectionString = ConfigurationManager.ConnectionStrings["MyEntities"].ConnectionString;
public IQueryable<MyObject> GetMyObjects(string database)
{
_db = new MyEntities(entityConnectionString.Replace("__REPLACE_ME__", database));
return _db.MyObjects
}
感謝,該解決方案看起來好多了。將GetMyObjects中的第二行更改爲「var scsb = new SqlConnectionStringBuilder(ecsb.ProviderConnectionString);」。 – 2010-11-02 07:19:02
呃,是的;我正是這個意思.... – 2010-11-02 10:57:02