我认为,这可以解决您的问题:
在Models \ IdentityModels.cs你可以重新定义你自己的用户模型:
public class ApplicationUser : IdentityUser
{
/* identity field from database */
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
[Required]
public bool Internal { get; set; }
public string UserFullName { get; set; }
public string UserEmail { get; set; }
public ApplicationUser()
: base()
{
Internal = false;
}
public ApplicationUser(string userName)
: base(userName)
{
Internal = false;
}
}
现在您可以使用OnModelCreating()覆盖和ToTable()方法更改默认 AspNet 表的映射:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Change the name of the table to be Users instead of AspNetUsers
modelBuilder.Entity<IdentityUser>().ToTable("User");
modelBuilder.Entity<ApplicationUser>().ToTable("User");
modelBuilder.Entity<IdentityRole>().ToTable("Role");
modelBuilder.Entity<IdentityUserClaim>().ToTable("User_Claim");
modelBuilder.Entity<IdentityUserLogin>().ToTable("User_Login");
modelBuilder.Entity<IdentityUserRole>().ToTable("User_Role");
}
}
最后,您将在数据库中看到以下表格:
User、Role、User_Role、User_Claim、User_Login而不是 AspNetUsers、AspNetRoles、AspNetUsersRoles、AspNetUsersClaims、AspNetUserLogins。
当然,User表将包含其他字段:UserId(int 身份)、Internal、UserFullName和UserEmail。