Warm tip: This article is reproduced from serverfault.com, please click

How can I change default ASP.NET Identity table names in .NET CORE?

发布于 2017-01-03 11:30:03

I've started with .NET Core, in MVC 5 I changed default table names for example: AspNETUsers to Users in this way and it worked perfectly: In IdentityModels Class I dded:

protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<IdentityUser>().ToTable("Users").Property(p => p.Id).HasColumnName("UserId");
        modelBuilder.Entity<ApplicationUser>().ToTable("Users").Property(p => p.Id).HasColumnName("UserId");
        modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles");
        modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins");
        modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims");
        modelBuilder.Entity<IdentityRole>().ToTable("Roles");
    }

But it does not work in .NET CORE (MVC 6). Can Anyone help me? Thanks a lot.

Questioner
Archil Labadze
Viewed
0
Set 2017-01-03 19:53:09

Try to change binding to

builder.Entity<ApplicationUser>(entity =>
       {
           entity.ToTable(name:"Users");
           entity.Property(e => e.Id).HasColumnName("UserId");

       });