Asp.net 已重命名默认表,但仍在创建AspNetusers表
我正在使用ASP.NET标识。我使用以下代码重命名了默认表Asp.net 已重命名默认表,但仍在创建AspNetusers表,asp.net,asp.net-identity,Asp.net,Asp.net Identity,我正在使用ASP.NET标识。我使用以下代码重命名了默认表 public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false) { } public static ApplicationD
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
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类ApplicationDbContext:IdentityDbContext
我希望我在重新回答这个问题时没有违反StackOverflow的指导方针///如果是这样,请提前道歉 在寻找快速解决方案时无意中发现了这篇文章-现在我已经对代码进行了一点挖掘并找到了答案;也许这对某人有帮助
我想您已经覆盖了默认的IdentityUser类,对吗
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
...
公共类应用程序用户:IdentityUser
{
公共异步任务GenerateUserIdentityAsync(用户管理器)
...
在这种情况下,您必须从ModelBuilder中排除默认的IdentityUser:
protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
//modelBuilder.Entity<IdentityUser>().ToTable("Users", "dbo"); // we have overwritten IdentityUser, so no more need for the empty AspNetUsers table
modelBuilder.Entity<ApplicationUser>().ToTable("Users", "dbo"); // Use ApplicationUser instead
modelBuilder.Entity<IdentityRole>().ToTable("Roles", "dbo");
protectedoverride void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
{
基于模型创建(modelBuilder);
//modelBuilder.Entity().ToTable(“Users”,“dbo”);//我们已经覆盖了IdentityUser,因此不再需要空的AspNetUsers表
modelBuilder.Entity().ToTable(“用户”、“dbo”);//改用ApplicationUser
modelBuilder.Entity().ToTable(“角色”、“dbo”);