[英]How to use ABP framework for existing database
ABP Framework is getting popular day by day and I want to use it for existing and new projects. ABP 框架日益流行,我想将它用于现有和新项目。 The problem is, ABP is designed for code first approach.问题是,ABP 是为代码优先方法设计的。 It is very good, but how can we use it for existing databases?它非常好,但是我们如何将它用于现有数据库?
There are some recommendations but they are not suitable for Sql Server or requires Abp Suite Tool.有一些建议,但它们不适合 Sql 服务器或需要 Abp Suite 工具。
Set a new connection string to the existing database.设置到现有数据库的新连接字符串。 Create new contexts to use it.创建新的上下文来使用它。 Then you produce the entities based on your existing tables.然后根据现有表生成实体。 At this point it is like working on any ABP other project.在这一点上,就像在任何 ABP 其他项目上工作一样。 Make Dto's, apps and services.制作 Dto 的应用程序和服务。 The only real gotcha to the plug and play world of Abp is the fact it likes the main column to be Id. Abp 的即插即用世界唯一真正的问题是它喜欢将主列设为 Id。 With that in mind you may need to go down the road of custom Entities .考虑到这一点,您可能需要走自定义Entities的道路。 Even build out audit interfaces for how your original tables are setup.甚至为原始表的设置方式构建审计接口。
There are 2 basic steps about your question.关于您的问题有两个基本步骤。
Step 1 Create New DbContext inside of EntityframeworkCore layer.(you need to configure related field for your Second DbContext Name)第 1 步在 EntityframeworkCore 层内创建新的 DbContext。(您需要为您的第二个 DbContext 名称配置相关字段)
Step 2 Inside of EntityframeworkCoreModule.cs, you should configure like this:步骤 2在 EntityframeworkCoreModule.cs 中,您应该像这样配置:
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<SecondDbContext>(options =>
{
options.AddDefaultRepositories(includeAllEntities: true);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.