Customize Identity Table

I have already created ASP.NET MVC Template and its structure look like this.
 
 
Now go to Model folder and open the IdentityModels.cs  class and  modify,  
  1. using Microsoft.AspNet.Identity.EntityFramework;  
  2. namespace Demo.Models  
  3. {  
  4.     // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.  
  5.     public class ApplicationUser: IdentityUser {}  
  6.     public class ApplicationDbContext: IdentityDbContext < ApplicationUser >  
  7.       {  
  8.         public ApplicationDbContext(): base("DefaultConnection") {}  
  9.             // add this code    
  10.         protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)  
  11.         {  
  12.             base.OnModelCreating(modelBuilder);  
  13.             modelBuilder.Entity < ApplicationUser > ().ToTable("tblCustomUser");  
  14.             modelBuilder.Entity < IdentityUserRole > ().ToTable("tblCustomUserRole");  
  15.             modelBuilder.Entity < IdentityUserLogin > ().ToTable("tblCustomUserLogin");  
  16.             modelBuilder.Entity < IdentityUserClaim > ().ToTable("tblCustomUserClaim");  
  17.             modelBuilder.Entity < IdentityRole > ().ToTable("tblCustomRole");  
  18.             modelBuilder.Entity < IdentityUser > ().ToTable("CustomUserLoginTable");  
  19.         }  
  20.     }  
  21. }  
Step 2: Enable Migration

Open package manager console and run  following command,
  1. enable-migrations
  2. add-migration customtable
  3. update-database
After run above command check the database table and its look like this,
 
 
So we converted default table  to new table name,
 
AspNetRoles               -->tblCustomRole
AspNetUserClaims     -->tblCustomUserClaim
AspNetUserLogins     -->tblCustomUserLogin
AspNetUserRoles       -->tblCustomUserRole
AspNetUser                -->CustomUserLoginTable
ApplicationUser         -->tblCustomUser
Ebook Download
View all
Learn
View all