EntityType'IdentityUserLogin'沒有定義鍵。定義此EntityType的鍵我正在使用Entity Framework Code First和MVC 5.當(dāng)我使用個(gè)人用戶帳戶身份驗(yàn)證創(chuàng)建我的應(yīng)用程序時(shí),我獲得了一個(gè)帳戶控制器以及所有必需的類和代碼,以使Indiv用戶帳戶身份驗(yàn)證工作。已經(jīng)存在的代碼包括:public class ApplicationDbContext : IdentityDbContext<ApplicationUser>{
public ApplicationDbContext() : base("DXContext", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}}但后來我繼續(xù)使用代碼創(chuàng)建了我自己的上下文,所以我現(xiàn)在也有以下內(nèi)容: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; } }最后,我有以下種子方法為我添加一些數(shù)據(jù),同時(shí)開發(fā):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");
}我的解決方案構(gòu)建正常,但當(dāng)我嘗試訪問需要訪問數(shù)據(jù)庫的控制器時(shí),我收到以下錯(cuò)誤:DX.DOMAIN.Context.IdentityUserLogin :: EntityType'IdentityUserLogin'沒有定義鍵。定義此EntityType的鍵。DX.DOMAIN.Context.IdentityUserRole :: EntityType'IdentityUserRole'沒有定義鍵。定義此EntityType的鍵。我究竟做錯(cuò)了什么?是因?yàn)槲矣袃蓚€(gè)背景嗎
EntityType'IdentityUserLogin'沒有定義鍵。定義此EntityType的鍵
拉風(fēng)的咖菲貓
2019-07-26 15:16:02