Skip to content

Instantly share code, notes, and snippets.

@caco0516
Created May 12, 2016 20:26
Show Gist options
  • Save caco0516/1325588068e44fbe3021ea547279f39d to your computer and use it in GitHub Desktop.
Save caco0516/1325588068e44fbe3021ea547279f39d to your computer and use it in GitHub Desktop.
Change tables names of a new Web App Project in Visual Studio
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>().ToTable("Users");
modelBuilder.Entity<IdentityUser>().ToTable("Users");
modelBuilder.Entity<IdentityRole>().ToTable("Roles");
modelBuilder.Entity<IdentityUserClaim>().ToTable("Claims");
modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins");
modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles");
}
}
@caco0516
Copy link
Author

This is a example of how to change names of tables auto generated by VS template project . This is useful when you already have a database with this kind of data or just need database generate by this project , on other projects.

Has you can see you can change users table name from "AspNetUsers" to "Users", in example above you see all tables required by auth system , with a new name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment