I am stuck trying to get this output
Id | Name | Role
----------------------------
1 | John | Administrator
----------------------------
2 | Mary | Manager
----------------------------
3 | Sage | Editor
----------------------------
4 | Hank | Manager
I can make it work in LINQPad, but somehow I am unable to translate it to ASP.NET MVC.
from u in Users
from ur in u.Roles
join r in Roles on ur.RoleId equals r.Id
select new {
Id = u.Id,
Name = u.Name,
Role = r.Name,
}
How do I LINQ that in ASP.NET MVC 5 with Identity?
Just to be clear, I am looking for the JOIN query between Users and Roles.
If you are using ASP.NET Identity 2, you have to add some codes to AccountContoller. Add an
ActionResult
to getUserList
. You also neddApplicationDbContext
instance and get it fromOwinContext
:Update - if user has multiple roles: