Here is the implementation of the ApplicationDbContext OnModelCreating method for your case. This is actually just an IdentityDbContext OnModelCreating method, ignoring IdentityUserClaim and IdentityUserLogin objects.
Note that overriding OnModelCreating should not call the base.OnModelCreating method.
public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { protected override void OnModelCreating(DbModelBuilder modelBuilder) { // Needed to ensure subclasses share the same table var user = modelBuilder.Entity<ApplicationUser>() .ToTable("AspNetUsers"); user.HasMany(u => u.Roles).WithRequired().HasForeignKey(ur => ur.UserId); user.Ignore(u => u.Claims); user.Ignore(u => u.Logins); user.Property(u => u.UserName) .IsRequired() .HasMaxLength(256) .HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("UserNameIndex") { IsUnique = true })); // CONSIDER: u.Email is Required if set on options? user.Property(u => u.Email).HasMaxLength(256); modelBuilder.Entity<IdentityUserRole>() .HasKey(r => new { r.UserId, r.RoleId }) .ToTable("AspNetUserRoles"); var role = modelBuilder.Entity<IdentityRole>() .ToTable("AspNetRoles"); role.Property(r => r.Name) .IsRequired() .HasMaxLength(256) .HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("RoleNameIndex") { IsUnique = true })); role.HasMany(r => r.Users).WithRequired().HasForeignKey(ur => ur.RoleId); modelBuilder.Ignore<IdentityUserLogin>(); modelBuilder.Ignore<IdentityUserClaim>(); } }
Here are the relevant lines of code:
user.Ignore(u => u.Claims); user.Ignore(u => u.Logins); modelBuilder.Ignore<IdentityUserLogin>(); modelBuilder.Ignore<IdentityUserClaim>();
If necessary, this will lead to the following migration without the dbo.AspNetUserClaims and dbo.AspNetUserLogins :
CreateTable( "dbo.AspNetRoles", c => new { Id = c.String(nullable: false, maxLength: 128), Name = c.String(nullable: false, maxLength: 256), }) .PrimaryKey(t => t.Id) .Index(t => t.Name, unique: true, name: "RoleNameIndex"); CreateTable( "dbo.AspNetUserRoles", c => new { UserId = c.String(nullable: false, maxLength: 128), RoleId = c.String(nullable: false, maxLength: 128), }) .PrimaryKey(t => new { t.UserId, t.RoleId }) .ForeignKey("dbo.AspNetRoles", t => t.RoleId, cascadeDelete: true) .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true) .Index(t => t.UserId) .Index(t => t.RoleId); CreateTable( "dbo.AspNetUsers", c => new { Id = c.String(nullable: false, maxLength: 128), Email = c.String(maxLength: 256), EmailConfirmed = c.Boolean(nullable: false), PasswordHash = c.String(), SecurityStamp = c.String(), PhoneNumber = c.String(), PhoneNumberConfirmed = c.Boolean(nullable: false), TwoFactorEnabled = c.Boolean(nullable: false), LockoutEndDateUtc = c.DateTime(), LockoutEnabled = c.Boolean(nullable: false), AccessFailedCount = c.Int(nullable: false), UserName = c.String(nullable: false, maxLength: 256), }) .PrimaryKey(t => t.Id) .Index(t => t.UserName, unique: true, name: "UserNameIndex");