Change ASP.net identity default table names

Published on Tuesday, 7 February 2017

Due to only having one MSSQL Database with my Webhost I like to prefix my table names to separate them.

I run multiple small sites on my host, who are great, but I can't justify £50 per MSSQL instance, so this solution works for me.

To rename the table names, inside your ApplicationDbContext class, use the following code:

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

	modelBuilder.Entity().ToTable("Users");
	modelBuilder.Entity().ToTable("UserRoles");
	modelBuilder.Entity().ToTable("UserLogins");
	modelBuilder.Entity().ToTable("UserClaims");
	modelBuilder.Entity().ToTable("Roles");
}

Obviously, the section inside the .ToTable("") part is where you specify your bespoke name.