EntityType'IdentityUserLogin'没有定义键。定义此EntityType的键
我正在使用Entity Framework Code First和MVC 5.当我使用个人用户帐户身份验证创建我的应用程序时,我获得了一个帐户控制器以及所有必需的类和代码,以使Indiv用户帐户身份验证工作。
已经存在的代码包括:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>{
public ApplicationDbContext() : base("DXContext", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}}但后来我继续使用代码创建了我自己的上下文,所以我现在也有以下内容:
public class DXContext : DbContext{
public DXContext() : base("DXContext")
{
}
public DbSet<ApplicationUser> Users { get; set; }
public DbSet<IdentityRole> Roles { get; set; }
public DbSet<Artist> Artists { get; set; }
public DbSet<Paintings> Paintings { get; set; } }最后,我有以下种子方法为我添加一些数据,同时开发:
protected override void Seed(DXContext context){
try
{
if (!context.Roles.Any(r => r.Name == "Admin"))
{
var store = new RoleStore<IdentityRole>(context);
var manager = new RoleManager<IdentityRole>(store);
var role = new IdentityRole { Name = "Admin" };
manager.Create(role);
}
context.SaveChanges();
if (!context.Users.Any(u => u.UserName == "James"))
{
var store = new UserStore<ApplicationUser>(context);
var manager = new UserManager<ApplicationUser>(store);
var user = new ApplicationUser { UserName = "James" };
manager.Create(user, "ChangeAsap1@");
manager.AddToRole(user.Id, "Admin");
}我的解决方案构建正常,但当我尝试访问需要访问数据库的控制器时,我收到以下错误:
DX.DOMAIN.Context.IdentityUserLogin :: EntityType'IdentityUserLogin'没有定义键。定义此EntityType的键。
DX.DOMAIN.Context.IdentityUserRole :: EntityType'IdentityUserRole'没有定义键。定义此EntityType的键。
我究竟做错了什么?是因为我有两个背景吗
慕的地10843