【发布时间】:2016-05-02 05:25:32
【问题描述】:
在 aspnet 身份 2 中,我这样做是为了删除身份表的 AspNet 前缀:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<IdentityUser>().ToTable("Users");
modelBuilder.Entity<IdentityRole>().ToTable("Roles");
modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles");
modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims");
modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins");
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
但是,现在如果我尝试这样做:
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 Profile Profile { get; set; }
public string FullName { get; set; }
}
运行 Update-Database 后,Users 表中没有添加任何字段,但 AspNetUsers 表是 bck 并且具有 FirstName 和 FullName 字段:
如何让这些字段出现在用户表中..?
【问题讨论】:
-
你能展示你所有的 IdentityDbContext 类,而不仅仅是 OnModelCreating 吗?
-
您还需要通过添加
modelBuilder.Entity<ApplicationUser >().ToTable("Users");将ApplicationUser映射到与IdentityUser相同的表
标签: entity-framework asp.net-identity