EF6 Study Notes (a): Code first method to generate database and initialize database actual operation

Source: Internet
Author: User
Tags actionlink connectionstrings

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

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.