NeuCharFramework (NCF)
  • NCF - NeuCharFramework
  • Projects

    • Preparation
    • Basic Library Source Code Analysis
    • DynamicWebApiEngine
    • Deployment
  • Help

    • Online Resources
    • Q&A Community
    • QQ Group (147054579)
    • Senparc WeChat SDK
  • Gitee
  • GitHub
  • English
  • 简体中文
GitHub
  • NCF - NeuCharFramework
  • Projects

    • Preparation
    • Basic Library Source Code Analysis
    • DynamicWebApiEngine
    • Deployment
  • Help

    • Online Resources
    • Q&A Community
    • QQ Group (147054579)
    • Senparc WeChat SDK
  • Gitee
  • GitHub
  • English
  • 简体中文
GitHub
  • NCF Overview

    • NCF - NeuCharFramework
    • About NCF
    • Environment Requirements
    • Frontend and Backend Separation Mode
    • Introduction to Xncf Modules
  • Prepare Development

    • Get NCF Template Source Code
    • Using Visual Studio to Run NCF
    • Running NCF Using CLI
    • Installation
    • Admin Login
    • Admin Backend
    • appsettings.json Configuration
    • Module Management
    • Accessing Documentation
  • Configuration

    • Entry File
    • Database Settings
    • appsettings.json Configuration
    • Docker
    • Dapr
    • Configure Multi-Tenant
    • Redis Cache
  • Modular Development

    • NCF Modular Development Concept
    • Composition of Xncf
    • Create the First Xncf Module
    • Xncf Module Sample Detailed Explanation
    • Implement Your Own Business Logic
    • Update Xncf Module
    • How to Call Between Modules
    • Publish Xncf Module to nuget.org
    • Update Base Library
    • Xncf Module Development
    • Embedding Static Resource Files into NCF
    • Publish Local Nuget Package
    • Advanced
  • Database

    • Database Settings
    • Multi-Database Support
    • Specify Database
    • Update database migration files for the Senparc.Service project (Migrations)
    • Multi-Database Principle
    • DatabasePlant
    • Tarmac Operation Database Migration and Update
  • Unit Testing

    • NCF Unit Test Introduction
    • Start Development
    • Advanced
    • Appendix
  • Q&A

    • NCF Terminology
    • NCF FAQ
  • Release

    • New Features
    • Upgrade Guide
    • Logs

Update database migration files for the Senparc.Service project (Migrations)

Take updating the Senparc.Service project as an example for manual updates.

Usually, updating the database migration files for Senparc.Service is because certain entity information corresponding to the database has been added/modified/deleted in the NCF template project.

Modify the database using Code-First

For example, we added a property in the AdminUserInfo class:

Image Text

Generate migration files using EF Core's Add-Migration command

Since the Senparc.Service project is not a standard XNCF module (essentially it is an XNCF module, but the file structure is quite special), it cannot be directly operated using the Senparc.Xncf.XncfBuilder module in the Admin backend, otherwise, the system will generate files according to the XNCF directory structure (of course, this does not affect compilation).

We can use the command line, taking CMD command line as an example, enter the Senparc.Service directory:

E:\Senparc项目\NeuCharFramework\NCF\src\Senparc.Service>

Enter the command:

dotnet ef migrations add AddOpenId -c SystemServiceEntities_SqlServer -o Migrations/Migrations.SqlServer -s ../Senparc.Web.DatabasePlant

In the above command, AddOpenId is the name of this update and can be freely filled in. SystemServiceEntities_SqlServer refers to the database context (DbContext) implementation pointing to SQL Server. When we need to update the MySQL database at the same time, we can replace it with SystemServiceEntities_MySQL (note the actual class name, the class name may not fully reflect the database type).

Executing the command will complete the SQL Server migration file update:

Image Text

In the above image:

①: The command entered in the Senparc.Service directory

②: Shows the currently used database connection string

③: Shows the updated SQL Server database type, DbContext context class name, and other information

In VS, you can see the newly created 20210809155647_AddOpenId.cs file and the updated snapshot file SystemServiceEntities_SqlServerModelSnapshot.cs:

Image Text

Through the 20210809155647_AddOpenId.cs file, you can see that the OpenId property (corresponding to the column in the database table) has been added.

Image Text

Update the version number of Senparc.Service

We recommend that after updating the content, you also update the version number of Senparc.Service, treating it the same as a regular XNCF.

/Senparc.Service/XncfModules/Register.cs

Set the new Version parameter, such as:

public override string Version => "0.3.4-beta4";

Update the database

Using the CMD command line, execute the command in the Senparc.Service directory:

dotnet ef database update -c SystemServiceEntities_SqlServer -s ../Senparc.Web.DatabasePlant

Adjust SystemServiceEntities_SqlServer flexibly according to the database type

Image Text

In the above run result:

①: Execute the update database command ②: Prompt to complete the latest migration update

Comparison of database tables before and after

ImageStatus
Image TextBefore Update
Image TextAfter Update
Edit this page on GitHub
Last Updated:
Contributors: Jeffrey Su
Prev
Specify Database
Next
Multi-Database Principle