How to change table names for ASP.net Identity 2.0 with int ID columns?

前端 未结 2 1928
借酒劲吻你
借酒劲吻你 2020-12-04 11:58

I\'ve used ASP.net membership for years and am just starting to try out ASP.net Identity. They just released version 2.0 and which is supposed to support int pr

相关标签:
2条回答
  • 2020-12-04 12:44

    In the IdentityModel.cs file, I added the following code to the ApplicationDbContext class

    Notice the Model names are different that that names listed in the accepted answer

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
    
            modelBuilder.Entity<ApplicationUser>().ToTable("SystemUsers");
            modelBuilder.Entity<IdentityRole>().ToTable("SystemRoles");
            modelBuilder.Entity<IdentityUserRole>().ToTable("SystemUserRoles");
            modelBuilder.Entity<IdentityUserLogin>().ToTable("SystemUserLogins");
            modelBuilder.Entity<IdentityUserClaim>().ToTable("SystemUserClaims");
        }
    
    0 讨论(0)
  • 2020-12-04 12:49

    Grrr...... So after wasting a couple hours on this, I copied my rules and pasted them below the base.OnModelCreating(modelBuilder); line and everything worked properly. I didn't realize that the base method needed to be called first :(

    Everything is working properly now using the following configuration:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder); // This needs to go before the other rules!
    
        modelBuilder.Entity<User>().ToTable("Users");
        modelBuilder.Entity<Role>().ToTable("Roles");
        modelBuilder.Entity<UserRole>().ToTable("UserRoles");
        modelBuilder.Entity<UserLogin>().ToTable("UserLogins");
        modelBuilder.Entity<UserClaim>().ToTable("UserClaims");
    }
    
    0 讨论(0)
提交回复
热议问题