I have below four tables
Role table
User table
UserRole table
UserType table
default Asp.net identity having below tables like Asp.netusers,Asp.netRoles,Asp.netuserlogins,Asp.netuserclaims,Asp.netuserroles
My table doesn't match the same column name and some columns not available in my tables. can i use my own tables to utilize the feature of asp.net identity or else i need to follow the same columns used in Asp.netusers table to my User table.
Is that all columns necessary to add in my table ?
Already I have implemented asp.net identity EF database first approach with same default tables. I have separate role store and user store
context below here users,userroles are same default table as like in asp.net identity(asp.netusers,asp.netroles)
public partial class OVT_UserEntities : DbContext
{
public OVT_UserEntities()
: base("name=OVT_UserEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<UserClaim> UserClaims { get; set; }
public virtual DbSet<UserLogin> UserLogins { get; set; }
public virtual DbSet<UserRole> UserRoles { get; set; }
public virtual DbSet<User> Users { get; set; }
}
User class:
public partial class User : IUser<int>
{
}
Role class:
public partial class UserRole : IRole<int>
{
}
Now i want to use above four new tables(table design images above) instead existing table provided by asp.net identity. So i am not sure whether same all the tables and columns need to be added in my database to work on asp.net identity ?
Since you're using
Microsoft.AspNet.Identity
you should inherit your User fromIdentityUser
(namespaceMicrosoft.AspNet.Identity.EntityFramework
).Your classes should be defined like this:
USER
ROLE
USER-ROLE
USER-CLAIM
USER-LOGIN
You could extend the classes adding your own custom columns:
Now you have to define the stores:
and then your database context, inheriting from
IdentityDbContext
:In your database context (MyContext) you must override
OnModelCreating
so that you can make your columns, change types, tables names etc etc: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: