From the course: Learning ASP.NET Core MVC

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Represent the database using Entity Framework

Represent the database using Entity Framework

From the course: Learning ASP.NET Core MVC

Start my 1-month free trial

Represent the database using Entity Framework

- [Narrator] Now that we've got an HTML form that's posting validated data back to the server, let's use the Entity Framework library to save that data to a database. Entity Framework is an object relational mapper or ORM, which is really just a fancy way of saying that it's a tool that allows you to save and retrieve data to and from a relational database using objects rather than hand coded sequel queries. To start, I'll add a new class called blog data context to our project. Note that the name of this class is not important at all, you can name it any name that you like. Then, I'll have this new class inherit the Entity Framework base class, Db Context. In order to tell Entity Framework that we'll be using this class to represent our database. Notice how Visual Studio is highlighting the Db Context base class to indicate that it doesn't know what it is. So, go ahead and add a reference to the entity framework package to make that error go away. In order for the data context to…

Contents