I want to get the list of roles and the total number of users in each of the roles. So far, this works:
var result = (from r in _context.UserRoles
join u in _context.Users on r.UserId equals u.Id
group new { r, u } by new { r.RoleId } into grp
select new UserRoleModel { RoleId = (int)grp.FirstOrDefault().r.RoleId, NoOfUsers = grp.Count() }).ToList();
But it does not display roles that don't have any users in it. I have 12 roles, 7 of them have been assigned to at least one user, while the remaining 5 have not. I want to display all the roles with the number of users assigned to them, but if the roles have no users assigned to them (like those 5) I want it to return 0 as the number of users. Thanks