Getting a list of users with their assigned role in Identity 2

前端 未结 2 1579
再見小時候
再見小時候 2021-02-14 21:59

I am stuck trying to get this output

Id | Name   | Role
----------------------------
1  | John   | Administrator
----------------------------
2  | Mary   | Manag         


        
2条回答
  •  被撕碎了的回忆
    2021-02-14 22:37

    This will help you

        using(ApplicationDbContext db=new ApplicationDbContext())
        {
              var users = (from user in db.Users
                           from roles in user.Roles
                           join role in db.Roles
                           on roles.RoleId equals role.Id 
                           select new
                           {
                               user.UserName, 
                               role.Name
                           }).ToList(); 
        }
    

提交回复
热议问题