我有兩個項目的解決方案:ASP.NET 帶有EF6的Web項目和類庫。在老ASP.NET 4的世界,我曾與構造的DbContext類:在ASP.NET 5/EF中獲取數據庫連接字符串6
public MyModel() : base("name=MyModel") { }
然後在web應用程序,我在web.config中的連接字符串。我也有一個DefaultConnection值用於基於成員身份的識別。
現在我試圖去到ASP.NET 5.默認連接字符串以「新」方式工作(我從頭開始標識,最終我不會使用基於DB的身份驗證) - 我得到身份驗證正常。默認連接字符串位於appsettings.json中。但是,無論我嘗試了什麼,我都會收到錯誤No connection string named 'MyModel' could be found in the application config file
。我試着將name=MyModel
更改爲name=Data:AAOModel:ConnectionString
,建議here,但我仍然得到與新值相同的異常。
appsettings.json的有關部分是這樣的(我知道我可以分成config.json - 但它並沒有任何區別):
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=..."
},
"MyModel": {
"ConnectionString": "Server=dbserver;Database=BusinessDB..."
}
}
我也試着在啓動中使用ConfigureServices()
IdentityContext被添加到腳手架代碼中,並描述爲here。但是,我注意到IdentityContext派生自Microsoft.Data.Entity
,但我的MyModel派生自System.Data.Entity,而services.AddDbContext <>()不喜歡它。
目前感覺我嘗試了谷歌可以購買的所有排列組合。使用帶有EF6類庫的ASP.NET 5的正確方法是什麼?
你能否把你的全部源代碼,GitHub上? – user929794