我的意圖是下面的代碼繼承ApplicationUser並實現一種新的名爲Customer的用戶。具體到該用戶的信息需要被保存在一個名爲「客戶」 下面是ApplicationUser,客戶和ApplicationDbContext類一個單獨的表是用來繼承ApplicationUser拋出驗證錯誤
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("Data Source=.\\SQLEXPRESS;Initial Catalog=ETrading.DAL.DatabaseContext;Integrated Security=True", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
[Table("Customers")]
public class Customer : ApplicationUser
{
public int CustomerId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Status { get; set; }
public string BillingAddress { get; set; }
public string CustomerFullName
{get{
return (FirstName + " " + LastName);
} }
public string Remark { get; set; }
public ICollection<CustomerOrder> CustomerOrders { get; set; }
}
應用建立正常,但當我發出的添加,遷移的遷移命令包管理器控制檯,我得到這個錯誤,
One or more validation errors were detected during model generation:
ETrading.DAL.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.
ETrading.DAL.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.
IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined.
IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined.
我看到有Q &如#1,它說修復OnModelCreating方法,但這個項目不具備這樣的方法。