O'Reilly logo

ASP.NET Core: Cloud-ready, Enterprise Web Application Development by James Singleton, Valerio De Sanctis, Mugilan T. S. Ragupathi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting up DbContext

To interact with data as objects/entity classes, EF uses the Microsoft.EntityFrameworkCore.DbContext class also called DbContext or simply Context. This class is in charge of all the entity objects during execution, including populating them with data from the database, keeping track of changes, and persisting them to the database during CRUD operations.

We can easily create our very own DbContext class for our project, which we will call ApplicationDbContext, by performing the following tasks:

Right-click on the /OpenGameList/Data folder and add a new ApplicationDbContext.cs class. Fill it up with the following code:

using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required