I have below four tables
Role table
User table
Since you're using Microsoft.AspNet.Identity
you should inherit your User from IdentityUser
(namespace Microsoft.AspNet.Identity.EntityFramework
).
Your classes should be defined like this:
USER
public class User : IdentityUser
{
}
ROLE
public class Role : IdentityRole
{
}
USER-ROLE
public class UserRole : IdentityUserRole
{
}
USER-CLAIM
public class UserClaim : IdentityUserClaim
{
}
USER-LOGIN
public class UserLogin : IdentityUserLogin
{
}
You could extend the classes adding your own custom columns:
public class User : IdentityUser
{
public string CompanyName { get; set; }
}
Now you have to define the stores:
public class UserStore: UserStore
{
public UserStore(MyContext context)
: base(context)
{
}
}
and then your database context, inheriting from IdentityDbContext
:
public class MyContext : IdentityDbContext
{
public MyContext(): base("ConnectionString")
{
}
}
In your database context (MyContext) you must override OnModelCreating
so that you can make your columns, change types, tables names etc etc:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity()
.Property(p => p.Id)
.HasColumnType("int")
.IsRequired();
modelBuilder.Entity()
.Property(p => p.Id)
.HasColumnType("int")
.IsRequired();
modelBuilder.Entity()
.Property(p => p.RoleId)
.HasColumnType("int")
.IsRequired();
modelBuilder.Entity()
.Property(p => p.UserId)
.HasColumnType("int")
.IsRequired();
modelBuilder.Entity()
.Property(p => p.Id)
.HasColumnType("int")
.IsRequired();
modelBuilder.Entity()
.Property(p => p.UserId)
.HasColumnType("int")
.IsRequired();
modelBuilder.Entity()
.Property(p => p.UserId)
.HasColumnType("int")
.IsRequired();
modelBuilder.Entity()
.ToTable("Users");
modelBuilder.Entity()
.ToTable("Roles");
modelBuilder.Entity()
.ToTable("UserRoles");
modelBuilder.Entity()
.ToTable("UserClaims");
modelBuilder.Entity()
.ToTable("UserLogins");
}
Now you can use migrations to generate your tables.
I've update a github project to reflect your situations.
UPDATE:
If you want to customize names and types of your columns you simply have to give them a name:
modelBuilder.Entity()
.Property(p => p.Id)
.HasColumnName("user_id")
.HasColumnType("SMALLINT")
.IsRequired();