0
這是我的問題。動態連接字符串與EF4,獲取元數據路徑無效
我爲我的實體框架上下文使用動態連接字符串。
//In Web Config
add key="DataSource" value="WIN-QBRH0MJL8IT\ISS" />
//In my EntityFactory.cs
public static DBEntities GetEntity()
{
var scsb = new SqlConnectionStringBuilder();
scsb.DataSource = ConfigurationManager.AppSettings["DataSource"];
scsb.InitialCatalog = "db1";
scsb.MultipleActiveResultSets = true;
scsb.IntegratedSecurity = true;
if (HttpContext.Current.Session["DBName"] == null)
{
HttpContext.Current.Response.Redirect("/Account/Step1");
}
else
{
scsb.InitialCatalog = HttpContext.Current.Session["DBName"].ToString();
}
var builder = new EntityConnectionStringBuilder();
builder.Metadata = "metadata=~/bin/Models/DBModel.csdl|~/bin/Models/DBModel.ssdl|~/bin/Models/DBModel.msl";
builder.Provider = "System.Data.SqlClient";
builder.ProviderConnectionString = scsb.ConnectionString;
DBEntities db = new DBEntities(builder.ConnectionString);
return db;
}
我知道問題是這一行:
builder.Metadata = 「元數據=〜/斌/型號/ DBModel.csdl |〜/斌/型號/ DBModel.ssdl | 〜/倉/型號/ DBModel.msl「;
我檢查和CSDL,SSDL,MSL在/mvcinfosite/bin/Models/.csdl,.ssdl,.msl
我EDMX的配置是:
元神器處理:複製到輸出目錄
以下是完整的錯誤
指定的元數據路徑無效。的有效路徑必須是 現有的目錄,用擴展名「.csdl」, 「.ssdl」現有的文件,或「.msl」,或一個URI標識的嵌入式資源
由於