简体   繁体   English

如何对现有数据库使用 ABP 框架

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

相关问题 如何在ABP框架中使用带有SQLite的真实数据库? - How to use real DB with SQLite in ABP framework? 如何将Entity Framework与现有数据库和Poco结构一起使用 - How to use Entity Framework with an existing Database and Poco Structure 使用Key vault存储ABP Framework的默认连接字符串 - Use Key vault to store default connection string of ABP Framework 如何使用Entity Framework在现有SQL Server数据库中创建表? - How to use Entity Framework to just create a table in an existing SQL Server database? 实体框架(现有数据库) - Entity Framework (existing database) 是否可以将 Entity Framework Core 与没有主键的表上的现有数据库一起使用? - Is it possible to use Entity Framework Core with existing database on tables with no primary key? 无法在使用Effort框架的单元测试中使用现有数据库 - Unable to use existing database in unit tests with Effort framework 使用实体框架部署 LocalDB - 不会使用现有数据库 - Deploying LocalDB with Entity Framework - won't use existing database includeDetails 在 ABP 框架中不起作用 - includeDetails not working in ABP Framework 实体框架首先在现有数据库中的单个新架构上使用代码 - entity framework use code first on single new schema in existing database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM