I have a solution with two projects: ASP.NET 5 Web project and Class library with EF6. In old ASP.NET 4 world I had DbContext class with the constructor:
public MyModel() : base("name=MyModel") { }
And then in the web application I had connection string in web.config. I also have a DefaultConnection value that I used for Membership-based identification.
Now I am trying to get to ASP.NET 5. Default Connection string works in the "new" way (I am starting identity from scratch and eventually I will not use DB-Based authentication anyway) - I am getting authenticated properly. Default connection string is in appsettings.json. However, no matter what I tried, I am getting an error No connection string named 'MyModel' could be found in the application config file
. I tried changing name=MyModel
to name=Data:AAOModel:ConnectionString
as suggested here but I still get the same exception with the new value.
Relevant part of appsettings.json is this (I realize that I can split into config.json - but it doesn't make any difference):
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=..."
},
"MyModel": {
"ConnectionString": "Server=dbserver;Database=BusinessDB..."
}
}
I also tried to use ConfigureServices()
in Startup the way IdentityContext is added in the scaffolded code and as described here. However, I noticed that IdentityContext is derived from Microsoft.Data.Entity
but my MyModel is derived from System.Data.Entity, and services.AddDbContext<>() doesn't like it.
At this time it feels that I tried all permutations that Google can buy. What is the right way to use ASP.NET 5 with EF6 class library?