简体   繁体   English

如何使用相同的数据库分离 ASP.Net Core 应用程序

[英]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.

相关问题 如何在 ASP.NET Core web 应用程序中使用 Entity Framework Core 从数据库中保存和检索图像? - How to save and retrieve images from database using Entity Framework Core in ASP.NET Core web application? 在ASP.NET核心应用程序中将其与EF核心一起使用时,如何加密postgres数据库的几列? - How encrypt few columns of postgres database while using it with EF core in an ASP.NET core application? 如何在相同解决方案的asp.net核心Razor页面中使用单独的asp.net核心web api - How to Use separate asp.net core web api in asp.net core Razor Page in Same Solution 如何通过ASP.NET Core中的“使用”打开数据库连接? - How to open a database connection through “using” in ASP.NET Core? 如何使用 asp.net 核心 mvc 6 将图像插入数据库? - How to insert images into database using asp.net core mvc 6? 在内存数据库提供程序中使用EF core进行asp.net core应用程序的单元测试的优势 - Advantages of using EF core in memory database provider for unit testing of asp.net core application 在 ASP.NET 核心 3 中使用来自单独 class 的集线器 - Using Hub from separate class in ASP.NET Core 3 如何使用实体框架使用“核心”数据库和各个派生数据库来构造ASP.NET MVC应用程序? - How can I structure an ASP.NET MVC application with a “Core” database and individual derived databases using Entity Framework? 如何使用MS SQL Server数据库发布和部署Asp.net核心数据库优先应用程序 - How to publish and deploy an Asp.net Core Database first application with MS SQL Server Database 如何在类/单独线程ASP.Net Core中使用ApplicationDbContext - How to use ApplicationDbContext in a Class / Separate Thread ASP.Net Core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM