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:
- From
Solution Explorer, right-click on the/Data/folder we created a while ago and add a newApplicationDbContext.csclass file. - Fill it up with the following code:
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
namespace TestMakerFreeWebApp.Data
{
public class ApplicationDbContext : DbContext
{
#region Constructor
public ApplicationDbContext(DbContextOptions...