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:
- User profiles stored in AspNetUsers. section 23.3.3
- Claims, external-login data, and tokens associated with users. section 23.3.3
- Migration history through the standard EF Core migrations table. section 23.3.3
