Reputation: 2862
I have derived a class from IdentityUser, CustomUser. If I check the database tables, I can see that Identity 2.0 has added a third column to AspNetUserRoles table, called CustomUser_Id.
It seems a foreign key to my CustomUser table, but AspNetUserRoles already has UserId column, so it seems redundant.
Why? What I am missing?
Upvotes: 0
Views: 968
Reputation: 239260
I'm assuming you've also got ApplicationUser
hanging around. IdentityUser
is an abstract class, so the column in dbo.AspNetUserRoles
is attached to whatever concrete class is used as the TUser
type for the generic IdentityDbContext<TUser>
. By default, that's ApplicationUser
. If you created another subclass of IdentityUser
, all you've done is create a class with similar properties, but one which is totally disconnected from all the Identity stuff and has its own table, dbo.CustomUsers
probably, which then requires a separate foreign key to be added on dbo.AspNetUserRoles
for it.
Long and short, you only get one bite at the user apple. If you want to have different types of users, they need to inherit from your main user implementation (ApplicationUser
by default), not IdentityUser
.
Upvotes: 4