liveBook · Manning

IdentityDbContext

As explained in ASP.NET Core in Action, 3e

IdentityDbContext<TUser> is an Entity Framework Core database context base class that maps ASP.NET Core Identity data for a specified user type.

IdentityDbContext<TUser> is an Entity Framework Core database-context base class for storing ASP.NET Core Identity accounts. An application context inherits from it and supplies a user type derived from IdentityUser. section 23.3.3 section 23.4.2

Add Identity to an application context

Define an ApplicationUser type, then inherit from IdentityDbContext<ApplicationUser>. Existing application entities, such as Recipe, can remain in the same context. This adds Identity entities to EF Core’s model; create and apply a migration to create the corresponding database schema. section 23.4.2

Listing 23.5 Updating AppDbContext to use IdentityDbContext
public class AppDbContext : IdentityDbContext<ApplicationUser>    #1
{
    public AppDbContext(DbContextOptions<AppDbContext> options)   #2
        : base(options)                                           #2
    { }                                                           #2
 
    public DbSet<Recipe> Recipes { get; set; }                    #2
}
#1 Updates to inherit from the Identity context instead of directly from DbContext
#2 The remainder of the class remains the same.

Shows the compact ApplicationDbContext declaration, including the generic Identity context, constructor, and existing application DbSet. section 23.4.2

The inherited context supplies Identity’s persistence model, including:

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains inheritance, Identity entities, schema changes, and migrations, but stops short of direct table interaction.
Examples
Uses ApplicationUser, AppDbContext, Recipe, Identity tables, and dotnet ef migration commands as concrete examples.
What it assumes
Uses an existing EF Core context and migration workflow while introducing IdentityUser-based custom user types.
What you can do after
Configure Identity persistence by deriving an application context from IdentityDbContext<TUser> and applying its migration.
How it connects
Connects EF Core, DbContext, IdentityUser, ApplicationUser, migrations, and ASP.NET Core Identity.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.