[英]How to a separate ASP.Net Core Application using same Database
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.我有一个现有的 ASP.Net Core Web API,现在我想将管理模块创建为单独的 ASP.Net Core 应用程序,但共享相同的数据库。
My problem now is how to handle my DBContext in the new solution especially because of the the following line containing the ApplicationUser model我现在的问题是如何在新解决方案中处理我的 DBContext,尤其是因为以下行包含 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.以及现有解决方案中存在的其他 model 类,我需要从中创建我的 DBSet 实体集以使我能够查询数据库。
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.如果可以使用 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.我将 ASP.Net Core 5 与 Entity Framework Core 一起使用,但如果它提供了解决方案,我可以迁移到版本 6。
You need to create a model as a separate (third) project, build a nuget
of that Model project and include it in both.您需要创建一个 model 作为单独的(第三个)项目,构建该
nuget
项目的 nuget 并将其包含在两者中。 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
).这非常简单(并且可能从
ASP.NET Core 1
开始)。
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 https://www.tutorialspoint.com/entity_framework/entity_framework_multiple_dbcontext.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.