【发布时间】:2019-01-16 05:18:29
【问题描述】:
我正在尝试通过忽略OnModelCreating 中的一些默认身份表来删除它们,如下所示:
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>(p => p.HasOne(e=>e.Department).WithOne().IsRequired());
modelBuilder.Ignore<IdentityUserToken<string>>();
modelBuilder.Ignore<IdentityUserClaim<string>>();
modelBuilder.Ignore<IdentityUserLogin<string>>();
modelBuilder.Ignore<IdentityRoleClaim<string>>();
modelBuilder.Ignore<IdentityUser<string>>();
}
}
在 startup.cs 我配置了如下身份:
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddDefaultUI(UIFramework.Bootstrap4)
.AddEntityFrameworkStores<ApplicationDbContext>();
当我注册用户时,一切正常,但是当用户尝试登录时,它会抛出此错误:
无法为“IdentityUserClaim”创建 DbSet,因为这 上下文模型中不包含类型
我在配置中遗漏了什么?
请不要将其标记为重复,因为我搜索了很多但无法找到合适的解决方案
【问题讨论】:
标签: asp.net-core asp.net-core-identity