This paper is to consolidate the foundation
The code first used above creates the database
This article uses the database generation model
This uses the ADO Entity Data Model to generate the model
Follow the instructions below to complete the operation
Here's a look at how to use this framework
Data access modifications are primarily implemented through context classes, which are in MyModel.Context.cs
Public Partial classMydbentities:dbcontext { Publicmydbentities ():Base("name=mydbentities") { } protected Override voidonmodelcreating (Dbmodelbuilder modelBuilder) {Throw Newunintentionalcodefirstexception (); } PublicDbset<students> Students {Get;Set; } }
We can use this context class like this
Public class Homecontroller:controller { // // GET:/home/ Private ReadOnly Mydbentities _db=New mydbentities (); Public actionresult Index () { return View (_db. Students.tolist ()); } }
Index view
@model ienumerable<mvcdemo9.models.students>@{ "Index";} @{ foreach (var in Model) { <p> @value. Studentname</p> }}
Run results
ASP. NET MVC Learning path-6