Setting up the DbContext

To interact with data as objects/entity classes, Entity Framework Core uses the Microsoft.EntityFrameworkCore.DbContext class, also called DbContext or simply Context. This class is in charge of all the entity objects during runtime, 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 doing the following:

  1. From Solution Explorer, right-click on the /Data/ folder we created a while ago and add a new ApplicationDbContext.cs class file.
  2. Fill it up with the following code:
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; ...

Get ASP.NET Core 2 and Angular 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.