The error message "Cannot create a DbSet for 'IdentityUser' this type is not included in the model for the context" occurs when your application's DbContext does not include the IdentityUser type.
To fix this issue, you need to add the IdentityUser type to your DbContext by inheriting from the IdentityDbContext class instead of the default DbContext class. The IdentityDbContext class includes the IdentityUser type by default.
Here is an example of how to inherit from the IdentityDbContext class:
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
In this example, the ApplicationDbContext class inherits from the IdentityDbContext class with the ApplicationUser type parameter. The ApplicationUser class should be the custom user type that you created to extend the IdentityUser class. If you did not create a custom user type, you can use the IdentityUser type directly.
After you've updated your DbContext, you should also update the services.AddDbContext method in your Startup class to use your custom DbContext, like this:
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
In this example, the ApplicationDbContext class is used as the type parameter for the AddDbContext method.
Once you've made these changes, you should be able to create a DbSet for the IdentityUser type in your DbContext without encountering the error message.
"ASP.NET Core 2.1 IdentityUser DbSet error"
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
// Your context implementation
}
ApplicationDbContext that inherits from IdentityDbContext<ApplicationUser> to resolve the IdentityUser DbSet issue."ASP.NET Core 2.1 IdentityUser not recognized in DbContext"
public class ApplicationUser : IdentityUser
{
// Your ApplicationUser class implementation
}
ApplicationUser class that inherits from IdentityUser to address the IdentityUser not recognized issue."ASP.NET Core 2.1 IdentityUser not part of model for context"
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
Startup.cs to use ApplicationUser and ApplicationDbContext for DbSet inclusion."AspNetCore IdentityUser DbSet missing"
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
ApplicationDbContext includes the necessary base constructor with options to resolve IdentityUser DbSet missing issues."Cannot create DbSet for IdentityUser IdentityDbContext"
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
ApplicationDbContext that inherits from IdentityDbContext<ApplicationUser>."IdentityUser not part of DbContext in ASP.NET Core"
public class ApplicationUser : IdentityUser
{
// Your ApplicationUser class implementation
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
ApplicationUser and ApplicationDbContext to ensure IdentityUser is part of the DbContext."ASP.NET Core IdentityUser not recognized in DbContext"
public class ApplicationUser : IdentityUser
{
// Your ApplicationUser class implementation
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
ApplicationUser and ApplicationDbContext."AspNetCore IdentityUser DbSet not found"
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
ApplicationDbContext inherits from IdentityDbContext<ApplicationUser>."IdentityUser not part of DbContext in IdentityDbContext"
public class ApplicationUser : IdentityUser
{
// Your ApplicationUser class implementation
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
ApplicationUser and ApplicationDbContext to ensure IdentityUser is part of the IdentityDbContext."ASP.NET Core IdentityUser DbSet error after upgrade"
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
ApplicationDbContext inherits from IdentityDbContext<ApplicationUser>.ng2-file-upload excel-udf cross-compiling uiscrollviewdelegate data-extraction screen hbm2ddl ipad digital-persona-sdk generalized-linear-model