Entity framwork (EF) 7--developing MVC New project even on the database now

Source: Internet
Author: User

First, development background:

Since the old system has been unable to meet the actual business requirements, it is necessary to develop new projects even on existing databases.

Second, the difficulty point:

The EF is not allowed by default when you want to delete an existing database table and recreate it. When you create a database object, you are prompted to "an object named ' XXXXX ' already exists in the database"

Third, the solution:

1. Create test database.

2. Create database objects (within VS project).

3. Add the object to DbContext (Applicationdbcontext).

Public dbset< Database object class > object name {get;set;}

4. Add migrations using "DNX EF migrations Add XXX" within the Project console window

5. DNX EF Database Update to create the databases.

6. Copy the contents of the Applicationdbcontextmodelsnapshot.cs/migratonxxx.cs/migrationxxx.designer.cs to the file.

Iv. migrating database objects to the official database

1, modify the database connection "Appsettings.json=>connection" to the official database.

2. Use "Dnx EF migrations Remove" in the Project console window to remove the new migrations.

3. Add the Migratons content that has been copied to the system migration and ApplicationDbContextModelSnapshot.cs.

4. DNX EF Database Update.

V. EF7 has established a connection with the official database.

Entity framwork (EF) 7--developing MVC New project even on the database now

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.