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