Using Identity DbContext and DbContext in a class library in ASP.NET Core

asp.net-core asp.net-identity entity-framework-core

Question

I have a .NET Core 2.0 solution which contains a class library project and an ASP.NET MVC project. The MVC project reference the class library. Class library has all the entity classes and DbContext using EF Core. Everything was fine up to that.

Then I added ASP.NET Identity to the MVC project. It creates a separate IdentityDbContext to create the identity-related entities. I want relationships (foreign keys) between the Identity user entity and some of my other entities (I am using code first migrations). And I don't want to do migrations twice from both DbContextes. What is the correct approach to use here?

1
0
7/24/2018 9:00:02 AM

Popular Answer

Combine your two contexts into one. In other words, just make your original context inherit from IdentityDbContext, instead of DbContext and dump the one the Identity scaffold created for you.

1
7/24/2018 2:04:55 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow