I have a LINQ TO SQL query which retrieves all the users along with their roles:
var userRoles = from u in db.GetTable<User>()
join ur in db.GetTable<UserRole>()
on u.UserID equals ur.UserID
join r in db.GetTable<Role>()
on ur.RoleID equals r.RoleID
orderby u.UserID
select new
{
u.UserID,
r.RoleName
};
A user in the system can have multiple roles. The result of this query (in a table format) looks like:
1 Admin
1 Employee
2 Employee
3 Employee
How can I re-write this query to return all user roles as comma separated values like:
1 Admin, Employee
2 Employee
3 Employee