简体   繁体   中英

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. The problem is, ABP is designed for code first approach. 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.

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. Make Dto's, apps and services. The only real gotcha to the plug and play world of Abp is the fact it likes the main column to be Id. With that in mind you may need to go down the road of custom 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)

Step 2 Inside of EntityframeworkCoreModule.cs, you should configure like this:

public override void ConfigureServices(ServiceConfigurationContext context)
    {
            context.Services.AddAbpDbContext<SecondDbContext>(options =>
            {                    
                options.AddDefaultRepositories(includeAllEntities: true);
            });    
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM