用户表
[Table("Users")]
public class User : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User> 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;
}
[Required]
[Display(Name = "Name")]
public string Name { get; set; }
[Required]
[Display(Name = "Gender")]
public string Gender { get; set; }
[Required]
[Display(Name = "Date of birth")]
public string DateOfBirth { get; set; }
}
myContext类
public class myContext : IdentityDbContext<User>
{
public myContext() : base("DefaultConnection")
{
}
public static myContext Create()
{
return new myContext();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<IdentityUser>().ToTable("Users", "dbo");
modelBuilder.Entity<IdentityRole>().ToTable("Roles", "dbo");
modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles", "dbo");
modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims", "dbo");
modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins", "dbo");
}
}
这正在创建两个表
- aspnetusers-带有加法字段
- 用户 - 带有默认字段
请注意,我在这里缺少什么。我如何在Users
表中也有其他字段
您需要更改myContext
中的OnModelCreating
中的行:
modelBuilder.Entity<IdentityUser>().ToTable("Users", "dbo");
to:
modelBuilder.Entity<User>().ToTable("Users", "dbo");
现在,它正在创建两个表,因为您已经定义了IdentityUser
类型用于创建名为Users
的表,并且一个默认表正在针对IdentityUser
类型创建。