【发布时间】:2019-05-24 14:53:17
【问题描述】:
当我创建迁移时,出现错误,如下所示:
System.InvalidOperationException: Cannot create a DbSet for 'IdentityRole' because this type is not included in the model for the context.
System.InvalidOperationException: Cannot create a DbSet for 'UserApp' because this type is not included in the model for the context.
是的,我的上下文中没有此列,但在以前的版本中,没有它也可以工作。 我的代码是:
public class UserApp: IdentityUser
{
[PersonalData]
public int Year { get; set; }
[PersonalData]
public string Country { get; set; }
public List<Product> products { get; set; }
}
和上下文类:
public class ApplicationContext:DbContext
{
public ApplicationContext()
{
}
//public ApplicationContext(DbContextOptions options) : base(options) { }
public ApplicationContext(DbContextOptions<ApplicationContext> dbContext) : base(dbContext)
{
}
带有一些数据库集。在启动课上,我有:
services.AddIdentity<UserApp, IdentityRole>(o =>
{
o.Password.RequireDigit = false;
o.Password.RequireLowercase = false;
o.Password.RequireUppercase = false;
o.Password.RequireNonAlphanumeric = false;
o.Password.RequiredLength = 6;
})
.AddEntityFrameworkStores<ApplicationContext>()
.AddDefaultTokenProviders();
怎么了?真的在这个版本中,我必须将用户和角色的属性添加到我的上下文中?
【问题讨论】:
-
ApplicationContext:DbContext?那堂课完全是空的。那应该是ApplicationContext : IdentityDbContext... -
@camilo-terevinto,是的,我忘记了这一点,但在这种情况下没有什么改变。 ://
标签: c# asp.net-core entity-framework-core identity asp.net-core-identity