EF code first and efcodefirst

Source: Internet
Author: User

EF code first and efcodefirst

In the actual project, you may have designed the database and want to use EF code fist. You can add ADO in the project. select code first from the database when using the. NET object model. The model is automatically created based on the database table,

If you need to modify the table structure, you can directly modify it in the model. After the modification, You need to synchronize it to the database. You can follow the steps below to set it,

1. Enter enable-migrations in the VS package management console. After it is enabled, a directory named Migrations will be created in the folder.

2. In Configuration. cs generated in 1, modify the constructor code to: "AutomaticMigrationsEnabled = true;" ContextKey = "EFTest. TestModel ";

3. After saving the changes, enter "Update-Database-Force" in the "package management console", Press enter, and run again.

If an error occurs that the table already exists, delete or rename the table for the first time, and then run the table again. This error will not occur after modification, the existing database records are not deleted.

 

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.