This article is a mirror article of machine translation, please click here to jump to the original article.

View: 21182|Reply: 0

[.NET Core] (EntityFrameworkCore) EF Core automatically migrates and upgrades databases

[Copy link]
Posted on 11/25/2019 11:04:10 AM | | | |
1: Preliminary preparations

Prepare entities (corresponding to database tables), database operation classes, database connection strings, and database operation services.
Create an iteration file using the Add-Migration command

2. Automatically upgrade the database through the Database.Migrate() method, the code is as follows



The Migrate method is an extension method in the Microsoft.EntityFrameworkCore.Relational.dll package.

Attached, I encapsulated the method:

Finally, the code is executed, and a new database is successfully created, and there is a table __EFMigrationsHistory that is automatically generated to record the Migrations record.







Previous:Asp.net MVC JsonResult ignores the property
Next:Downloading the exe file in asp.net core returns a 404 error solution
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com