I am using Asp.net MVC and I want to rename identity tables such as AspNetUsers, AspNetRoles, AspNetUserRoles To Users, UserRole, UserwithRoles Please Can any one help me ?
Asked
Active
Viewed 1,385 times
1
-
1Possible duplicate of [How can I change the table names when using Visual Studio 2013 ASP.NET Identity?](https://stackoverflow.com/questions/19460386/how-can-i-change-the-table-names-when-using-visual-studio-2013-asp-net-identity) – Erik Philips Dec 01 '18 at 23:40
2 Answers
1
You have two options here:
Data Annotations:
//Changing database table name to Metadata
[Table("Users")]
public class AspNetUsers
{
[Required, Key]
public int Id { get; set; }
[Required, StringLength(250), DataType(DataType.Text)]
public string Name{ get; set;
}
or we have Fluent API:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//Changing Database table name to Metadata
modelBuilder.Entity<AspNetUsers>().ToTable("Users");
}
Using the Fluent API is the preferred option if you want to ensure your Domain Model stays uncluttered.

Luca La Malfa
- 121
- 7
0
You can give those tables a custom name of your choice in the OnModelCreating
method within your ApplicationDbContext.cs
file in the following way:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// custom code here...
modelBuilder.Entity<IdentityUser>().ToTable("User", "dbo");
modelBuilder.Entity<IdentityRole>().ToTable("Role", "dbo");
modelBuilder.Entity<IdentityUserRole>().ToTable("UserRole", "dbo");
modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaim", "dbo");
modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogin", "dbo");
modelBuilder.Entity<IdentityUserToken>().ToTable("UserToken", "dbo");
// other custom code here...
}

Darkseal
- 9,205
- 8
- 78
- 111