Entity Framework Code First migration command, codefirst

Source: Internet
Author: User

Entity Framework Code First migration command, codefirst

 

I. Enable-Migrations

  Note:Enable migration for the project. This command adds the Migrations folder for the project, including two files:

Configuration class: This class allows context-based Configuration migration.

InitialCreate migration: this migration is generated before migration is enabled. If the database is not generated before Migration is enabled, the file is not added to the project, but is generated when the "Add-Migration" command is called for the first time.

  Syntax: Enable-Migrations

 

2. Add-Migration

  Note:Based on the changes made to the model since the previous migration, a base frame is built for the next migration.

  Syntax: Add-Migration "[Name]"

Name: Migration display Name, which will constitute the generated migration file Name with the current generated file Timestamp

 

Iii. Update-DataBase

  Note:Migrate all pending applications and databases

  Syntax: Update-Database-[Option]

Option: Vcrbose displays the SQL statement executed by the migration on the console

TargetMigration: [Name] migration to a specific version. If you need to roll back to an empty database, you can write [Name] as $ InitialDatabase

Script is a Script generated for migration without execution.

SourceMigration: [Name] source migration

 

Iv. Automatic migration

  Note:When deploying an application, you want to automatically upgrade the database through a suspended migration when the application starts.

  Code: Database. SetInitializer (new MigrateDatabaseToLatestVersion <DbContext, Configuration> ());

 

[The above collection is easy to use, Do not spray]

Related Article

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.