From the course: Learning ASP.NET

Unlock the full course today

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

Data access with Entity Framework

Data access with Entity Framework

From the course: Learning ASP.NET

Start my 1-month free trial

Data access with Entity Framework

- [Instructor] We're ready to implement data access for our MVC application, and to do that, we'll use Entity Framework's Code First Approach. We've already defined the model that represents a Course. This entity class will be used to generate a database table that stores Course information. Notice the Id property. Entity Framework expects an entity to have a key property in order to track changes to it. By convention, Code First looks for a property named Id or a combination of the class name and Id, like Course Id. If the name doesn't follow convention, you can add a Key attribute like this. And we can go ahead and remove it. The required attribute on Name isn't just used by ASP.NET MVC, it's also for Entity Framework to ensure that this property has a value. Keep in mind that there's other attributes to customize the data configuration. To start using Entity Framework, we need to install the latest version using NuGet. Right-click on the References folder of the project and select…

Contents