Entity Framework Code First Database migration (DB migration)

Source: Internet
Author: User

First, manual migration

1th step, enable database migration

Open the Package Manager console

Package Manager, Tools---Library Package Manager console

After opening the console, in the Console Management window, enter the enable-migrations directive, the ammonium key down, to which the database migration has been enabled, but has not yet been executed, the results such as:

2nd step, run the database migration

In the Console Management window, enter the add-migration directive to add a database migration version that must be entered with a version name Add-migration Addproductcategorytypename, such as:

Once run, a new class is added to the Migrations folder in the solution, 201407030630269_addproductcategorytypename.cs

The 3rd step, formally to the database migration action, in the Controller window input update-database instructions can be executed, such as:

Second, automatic migration

1. Add a piece of code to the Application_Start () method inside the Global.asax class

2. Open in Migrations/configuration.cs class

Automaticmigrationsenabled = true;

3, every update must be executed in the window database migration Instructions Update-database

Third, automatic migration is not applied because automatic migration can lead to data loss resolution

Just run the add-migration Initial command in the console window and enter Update-database to perform the update.

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.