Use Mvc ef code first, mvcef

Source: Internet
Author: User

Use Mvc ef code first, mvcef

There are a lot of ways to use ef code first on the Internet, which is messy. below is my own summary. please correct me if there is anything wrong. I am a newbie!

1. Create a class library = reference and right-click manage NuGet package to add EntityFramework

In the class library, an App. config file will be added to open the string for adding your own database connection (create a local database)

2. Create an object (such as Student)

3. Create your own DbContext class (for example, testContext. cs)

 

4. Open the package Management Console: tool = Library Program Package Manager = Package Manager Console

Input: Enable-Migrations

One more Migrations folder in the class library will be found, and the Configuration. cs under the folder will be opened (changed to true)

 

5. On the console, enter Update-Database-Verbose (used when adding tables or fields)

In this way, the corresponding table and field are generated.

On the console, enter Update-Database-Force-Verbose (used to delete fields or tables)

6. Check the database to see the results.

 

The above is a process of your own use. It is relatively simple to post to you. Please note that I am a newbie

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.