Reputation: 1970
I have an existing ASP.Net Core Web API and now I want to create the admin module as a separate ASP.Net Core application but sharing the same database.
My problem now is how to handle my DBContext in the new solution especially because of the the following line containing the ApplicationUser model
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
and also the other model classes which exist in the existing solution from where I need to create my DBSet entitie sets to enable me query the database.
I wish to have the admin module to be a completely separate application hosted on a different domain/server but having access to the same database so that the admin can manage the database table entries from the admin solution.
I don't want it to be a separate project on the same solution. Rather I want it to be a completely separate solution/application which can be hosted independently.
I will appreciate any guide to achieving this if it is possible with ASP.Net Core.
I am using ASP.Net Core 5 with Entity Framework Core but I can migrate to version 6 if that offers a solution.
Upvotes: 1
Views: 1159
Reputation: 94
You can have multiple contexts for single database. It can be useful for example if your database contains multiple database schemas and you want to handle each of them as separate self contained area.
Read the link below
https://www.tutorialspoint.com/entity_framework/entity_framework_multiple_dbcontext.htm
Upvotes: 0
Reputation: 10078
You need to create a model as a separate (third) project, build a nuget
of that Model project and include it in both. There are some small challenges, since you are going to run migrations on this standalone project - but nothing that cannot be overcome
It's very straightforward (and possible since ASP.NET Core 1
).
Upvotes: 1