Customize table names in ASP.NET Identity
When using ASP.NET Identity in a project, the default table name prefix for user-related data is "AspNet". While these names may work for some scenarios, in some cases you may want to use custom table names.
Rename AspNetUsers table
To change the name of the AspNetUsers table, override the OnModelCreating method in the DbContext and provide the new table name:
<code class="language-csharp">protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<IdentityUser>().ToTable("MyUsers"); }</code>
Replace all AspNet table names
To replace all AspNet table names with your own, provide a custom name for each entity:
<code class="language-csharp">protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<IdentityUser>().ToTable("MyUsers").Property(p => p.Id).HasColumnName("UserId"); modelBuilder.Entity<ApplicationUser>().ToTable("MyUsers").Property(p => p.Id).HasColumnName("UserId"); modelBuilder.Entity<IdentityUserRole>().ToTable("MyUserRoles"); modelBuilder.Entity<IdentityUserLogin>().ToTable("MyUserLogins"); modelBuilder.Entity<IdentityUserClaim>().ToTable("MyUserClaims"); modelBuilder.Entity<IdentityRole>().ToTable("MyRoles"); }</code>
Note:
The above is the detailed content of How Can I Customize AspNet.Identity Table Names?. For more information, please follow other related articles on the PHP Chinese website!