0
我試圖構建3層應用程序模型。實體框架和Owin標識數據上下文
該模型使用Web API作爲表示層,業務層使用owin身份進行授權和用戶管理,最後是使用實體框架6的數據層。整個事情看起來像這樣(每層都是一個單獨的項目)
我有ProductEntitiesDataContext
什麼我嘗試做的是使用相同的DataContext
無論是數據層和Owin identity
。或者至少爲它們使用相同的連接字符串。
然而,當我通過我的ProductEntitiesDataContext到Owin類我得到異常的說法:
No connection string named 'ProductEntities' could be found in the application config file.
在引誘人使用相同的連接字符串我試圖做到這一點:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, Guid, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public ApplicationDbContext()
: base("ProductEntities")
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
,但它只是創造新的數據庫「ProductEntities」作爲名稱
我如何能重複使用的2層以上相同的數據上下文或者相同的連接字符串,請建議。
謝謝。
你必須在你的新項目的app.config中包含連接字符串,或者傳遞它。由於沒有找到ProductEntities作爲連接字符串的名稱,因此它假定它是連接字符串(即它的路徑) – DevilSuichiro