Code I update database structure __ Database

Source: Internet
Author: User
In Codefirst mode, when your entity classes change, there are several changes that support Automatic Updates:
A, adding attributes or classes
b, renaming properties and classes (you want to make them work, you need to write some scripts)//as little as possible
c, renaming columns (column) or tables (table), but not renaming attributes or classes
D, Delete properties


Here's how to do it:
1, to ensure that the project has been referenced entityframework (are already updating the data structure, of course, there are references), and ensure that all types of configuration are normal.
2, in the Package Manager console using the command enable-migrations, will be under the Project New Migrations folder and the corresponding file Configuration.cs.
If you have an error running the above command, you need to add a parameter when you run it again-force
3, modify the Configuration.cs configuration parameters.
Set Automaticmigrationsenabled to True
4, execute update-database command, update data structure.
When the Update-database command executes incorrectly, you can also add the-force parameter Force update
Note: A table with the name Dbo.__migrationhistory is automatically generated in the database, which is important to record all updated records beginning with the creation of the database, and do not move it.

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.