title: How to show data from two contexts in single view in ASP.NET Core
body: <p>I'm sorry for my poor command of English.</p>
  <p>To display a list of users for each consultant, I need to first display the first name, last name, phone number and field on a page in ASP.NET Core 5.</p>
  <p>To do this, I need to be able to merge <code>AspNetUsers</code> and <code>Students</code> tables so that I can take information from them and save it in the view model so that I can show it on one page.</p>
  <p>But the problem is that I can not merge these two tables. I even used the Join method in Linq, but I got an error.</p>
  <p>Needless to say, these two tables are already relationshiped and the only problem is the simultaneous display of information from these two contexts - one <code>IdentityDbContext</code> and other is <code>PlanContext</code>.</p>
  <p>Thank you!</p>
  <p>View model <code>Adminshowusers</code> :</p>
  <pre><code>public class Adminshowusers 
  {
       public string FirstName { get; set; }
       public string LastName{ get; set; }
       public string PhoneNumber{ get; set; }
       public string Field { get; set; }
  }
  </code></pre>
  <p>And my action method that did not work</p>
  <pre><code>public async Task&lt;IActionResult&gt; ConsultantIndex(string Msg,string id)
  {
      var data = await _userManager.GetAllUsersWithRolesAsync();
  
      var users = (from u in data
                   join a in _context.Students 
                          on data.Select(x=&gt;x.Id) equals a.ID
                   select new AdminAddUsers()
                              {
                                  FirstName = u.FirstName,
                                  LastName = u.LastName,
                                  PhoneNumber = u.PhoneNumber,
                                  Field = a.Field
                              });
  
      return View(users);
  }
  </code></pre>
  <p>Method <code>GetAllUsersWithRolesAsync()</code> is also pre-created and displays a list of all users along with their roles:</p>
  <pre><code>public async Task&lt;List&lt;UsersViewModel&gt;&gt; GetAllUsersWithRolesAsync()
  {
      return await Users.Select(user =&gt; new UsersViewModel
          {
              Id = user.Id,
              Email = user.Email,
              UserName = user.UserName,
              PhoneNumber = user.PhoneNumber,
              FirstName = user.FirstName,
              LastName = user.LastName,
              BirthDate = user.BirthDate,
              IsActive = user.IsActive,
              LastVisitDateTime = user.LastVisitDateTime,
              Image = user.Image,
              RegisterDate = user.RegisterDate,
              Roles = user.Roles.Select(u =&gt; u.Role.Name),
          }).ToListAsync();
  }
  </code></pre>