Reference Original Address:
Https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/ Creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
Note: The study notes refer to the process in the original text, in order to increase the practical operation, and can understand deeply, some places according to the actual situation to make some adjustments, and according to their own understanding to do some expansion.
My Learning Environment: VS2015 + EF 6.1.3 +. NET 4.5.1
Step1 : New Web Application (I'm named Eftest)
Select the blank template, but tick the MVC folder reference.
STEP2: install EF6 via package Manager console
Step3: Create a new localdb empty test database
STEP4: Create a new master page as the base portal (create a new empty controller in the controller directory, the name is home)
Then right-click on the Home Controller's index action to add the Index view: (Just choose an empty View, test it, it's easy)
and modify the Home/index view to the following code:
@{Viewbag.title="Hello EF6";}"Home","Index","Home") </li> <li> @Html. ActionLink (" About"," About","Home") </li> <li> @Html. ActionLink ("Students","Index","Student") </li> <li> @Html. ActionLink ("Courses","Index","Course") </li> <li> @Html. ActionLink ("Instructors","Index","Instructor") </li> <li> @Html. ActionLink ("Departments","Index","Department") </li> </ul></div>
STEP5: Adding a database string to Web. config;
<connectionStrings> <add name="schoolcontext" connectionstring=" Data source= (localdb) \projectsv13;initial catalog=eftest;integrated security=true; Connect timeout=30; Encrypt=false; Trustservercertificate=true; Applicationintent=readwrite; Multisubnetfailover=false; " providername="System.Data.SqlClient"/> </connectionstrings >
Note: You can click a database in SQL Server Object Explorer, and then in the property page, you can copy the connection string for that database;
EF6 Study Notes (a): Code first method to generate database and initialize database actual operation