Update the database using the Entity Framework's migration in the server

Source: Internet
Author: User
Tags management studio sql server management sql server management studio

In the development environment, every time we make changes to the database, such as adding table fields. After we have changed the entity class, we only need to run the Update-database script in the NuGet package Management console:

Update-database

This migration feature provided by the Entity framework is very convenient and basically no longer has to open SQL Server Management Studio. So how do we synchronize our database changes in the release environment (server)?

One way is to run the Update-database script with the-verbose or-script parameters:

Update-database-script

This will generate SQL scripts each time, copy the generated SQL scripts, and then go to the server to execute.

But this is very inconvenient, in case I was in the middle of a local execution and forgot to run the corresponding SQL script on the service? The trouble that this brings is unimaginable.

We have a better way of doing update-database on the server as well as locally.

The following are the specific practices:

Copy the/packages/entityframework6.1.3/tools/migrate.exe file to the bin directory of the server publishing environment.

Save the following cmd command as a Migrate.bat file:

Migrate.exe example.ef.dll/startupconfigurationfile= ". \web.config "Pause

Exmaple.EF.dll is the DLL that you write the project for Entity Framework migration.

Migrate.exe can also not be placed in the bin directory, you can use to create a separate folder (such as tools) to store, but need to put EntityFramework.dll and EntityFramework.SqlServer.dll into this folder. In addition, the command line also specifies the parameter/startupdirectory: "Bin full directory", and the/startupconfigurationfile parameter also provides the full Web. config path.

This makes it convenient for each publisher to run this bat file, and ensures that the server's database version is always synchronized with the local.

Update the database using the Entity Framework's migration in the server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.