以下のコードでは、ApplicationUserを継承し、Customerという新しい種類のユーザーを実装します。このユーザに固有の情報は、アプリケーションが正常にビルドを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; }
}
使用されている「お客様」 は以下ApplicationUser、顧客であり、ApplicationDbContextクラスと呼ばれる別のテーブルに保存する必要がありますが、私は追加-移行移行コマンドからを発行したときパッケージマネージャコンソール、私はこのエラーを取得し、
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 &は、それがOnModelCreatingメソッドを修正するために言いますが、このプロジェクトは、このような方法を持っていないのStackOverflowのようにありました見ました。