Using ASP.NET MVC5 user identity, I am trying to display IdentityUser's role names in view.
It seems like Identity user has Roles property, which represent collection of IdentityUserRole
, instead of IdentityRole
. The difference is IdentityUserRole
represents association between IdentityUser
and IdentityRole
, while IdentityRole
is the actual Role
model [+]. Apparently there is no navigation defined between IdentityUser and IdentityRole. So all we get is RoleId from IdentityUserRole
.
- Is there an easy way to get the roles names?
- Using Fluent API, can we define a virtual navigation property between
IdentityRole
andIdentityUserRole
to get name easily throughout the project? - If it is by design, what is the benefit of not letting us obtain
IdentityRole
straightforwardly?
You can select a userrole in identity using the rolemanager
from the user get the userrole and then select the name from that role