【发布时间】:2016-12-12 17:12:28
【问题描述】:
用户表
[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 表中也有其他字段
【问题讨论】:
标签: c# asp.net-mvc ef-code-first asp.net-identity