This project is read-only.

Why have UserRole class as a navigation property of IdentityUser?

Mar 31, 2014 at 2:01 PM
Edited Mar 31, 2014 at 2:02 PM
Before Identity 2.0 I had implemented 1.0 and implemented all of the classes I needed from the interfaces provided in the .Core library. I'm trying to use more of your implementation this go 'round and am trying to use the .EntityFramework implementations. I've noticed that the IdentityUser class has a navigation property mapping to the IdentityUserRole class which is only a link table in the database. Is this needed? Couldn't this be handled through foreign keys and just mapped out in a EF configuration mapping? This is how I had it set up previously with my implementation of it.

It seems odd and cumbersome to try and access the Roles from the User class by typing User.Roles[0].Role.Name to get the role name. It would be much easier to just have User.Roles[0].Name. It is also much clearer and easier to understand.

From the Role EFconfiguration you should have:
this.HasMany(t => t.Users)
                .WithMany(t => t.Roles)
                .Map(m =>
                        m.MapKey("RoleId", "UserId");
Apr 1, 2014 at 6:16 PM
@KPaxton1182: Thank you for pointing this out. I am taking this up with the team
Apr 2, 2014 at 6:54 PM
I ran into another issue which is somewhat related and have created an Issue for it regarding the AddRoleToUser method in the UserStore class.

This method takes forever with a larger dataset because it tries to pull back all the User information for the role before it can add a single UserRole item. This is not ideal and is a huge performance hole.

This is something that needs to be fixed ASAP.