我使用Asp.net身份。我想在表AspnetUserLogins(列名Firstname,Lastname)中添加一些额外的列。为此,我继承了类IdentityUserLogins
,如
public class ApplicationUserLogin : IdentityUserLogin
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
在应用程序中,我使用函数通过UserManager类向某些用户添加外部登录,这样:
ExternalLoginInfo eInfo = Context.GetOwinContext().Authentication.GetExternalLoginInfo();
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
IdentityResult result = manager.AddLogin(this.User.Identity.GetUserId(), eInfo.Login);`
一切正常。此代码将新记录添加到AspnetUserLogins
表,不幸的是将"IdentityUserLogin"
值插入Discriminator
列。是否有可能说UserManager<ApplicationUser>
类使用子类ApplicationUserLogin
而不是IdentityUserLogin
(并使用"ApplicationUserLogin"
值填充鉴别器列?
答案 0 :(得分:0)
为了使其正确,您需要更新所有IdentityUserLogin
相关表和继承,如下所示。
ApplicationUser:
public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, IdentityRole, IdentityUserClaim>
{
}
你的Db contenxt:
public class YourDataContext : IdentityDbContext<ApplicationUser , IdentityRole, string, ApplicationUserLogin, IdentityUserRole, IdentityUserClaim>
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUserLogin>().ToTable("TableName");
//Any relevant model bindings.
}
}