0

How can I get the identity users with their multiple assigned roles, I want the user's name and a list of roles to be seen, i am using blazor wasm and aspnet core. so far I have this, but I don't know if I'm on the right track or there are other alternatives instead of using projection:

var listado = await (from user in context.Users
                         join userRoles in context.UserRoles on user.Id equals userRoles.UserId
                         join role in context.Roles on userRoles.RoleId equals role.Id
                         select new { UserId = user.Id, UserName = user.UserName, RoleId = role.Id, RoleName = role.Name })
                        .ToListAsync();

With this code I get that each user is assigned their roles, but a user has more than one role and generates it for me 3 times, when I want the user to be generated once with his list of roles

Jasiel Torres
  • 383
  • 8
  • 18

1 Answers1

0

Widely answered here: Group by in LINQ. Check Jon Skeet's answer. Your roles would be the cars in that example.

mrbitzilla
  • 368
  • 3
  • 11