title: How to get a table of users and their roles in .core mvc?
body: <p>At first I have a table of users from <code>userManager</code> where I can search and sort by username. The original table is following  <a href="https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/sort-filter-page?view=aspnetcore-3.1" rel="nofollow noreferrer">microsoft .net tutorial</a>
  but now I am trying join the role of each user from <code>roleManager</code>. Tried to look for other solution in stackoverflow but I couldn't implement them into my code below. How should I revise my code to get the result from user from <code>userManager</code> and role from <code>roleManager</code> in one table?</p>
  
  <pre><code>public async Task&lt;IActionResult&gt; ListUsers(string sortOrder, string currentFilter, string searchString, int? pageNumber, string name)
          {
  
              ViewData["NameSortParm"] = String.IsNullOrEmpty(sortOrder) ? "userid" : "username";
              ViewData["DateSortParm"] = sortOrder == "Date" ? "date_desc" : "Date";
              var users = userManager.Users;
  
              if (searchString != null)
              {
                  pageNumber = 1;
              }
              else
              {
                  searchString = currentFilter;
              }
  
              if (!String.IsNullOrEmpty(searchString))
              {
                  users = userManager.Users.Where(u =&gt; u.Name.Contains(searchString));
              }
  
              switch (sortOrder)
              {
                  case "userid":
                      users = users.OrderByDescending(s =&gt; s.UserName);
                      break;
                  case "username":
                      users = users.OrderByDescending(s =&gt; s.Name);
                      break;
                  case "Date":
                      users = users.OrderBy(s =&gt; s.BirthDate);
                      break;
                  case "date_desc":
                      users = users.OrderByDescending(s =&gt; s.BirthDate);
                      break;
                  default:
                      users = users.OrderBy(s =&gt; s.UserName);
                      break;
              }
              int pageSize = 50;
              return View(await PaginatedList&lt;ApplicationUser&gt;.CreateAsync(users.AsNoTracking(), pageNumber ?? 1, pageSize));
              //return View(await users.AsNoTracking().ToListAsync());
          }
  </code></pre>