ASP. WebForm using Codefirst to create and modify database summaries

Source: Internet
Author: User

Use Codefirst to add and modify database file summaries under the asp.net4.5 framework.

Establish:

1. Building Model Classes

2. In package Manager Console, run the command:
enable-migrations -ContextTypeName ContosoUniversityModelBinding.Models.SchoolContext

3. The system automatically generates the Configuration.cs file, where the seed method is used to initialize the database

4. Run the commandupdate-database

5. The database file has been added

Modify:

1. Modify the field of the Model class

2, in the Package Management window, add a migration by running the command add-migration addenrollmentdate. Notice The migration code adds the new Datetime column to the Student table.

3, Therefore, open Configuration.cs in the Migrations folder and remove or comment out of the code in the seed method. Save and close the file.

4. Now, run the command update-database.

ASP. WebForm using Codefirst to create and modify database summaries

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.