title: How to retrieve Users with a specific role via Linq in ASPnet Identity
body: <p>I need to retrieve all users of a specific role, something I think should be made straightforward, however, here is the problem.</p>
  
  <p>The Roles navigation Property of ApplicationUser is not the list of roles (IdentityRole) but a collection of (IdentityUserroles) the intermediate table that links users and roles. So, this is the code I have, but it does not work.</p>
  
  <pre><code>[HttpPost]
  [Authorize(Roles = "Admin, Recepcionista, Orientador")]
  public ActionResult SearchResults(SearchCriteriaViewModel criteria)
  {
  
  
      List&lt;SearchResultViewModel&gt; results = new List&lt;SearchResultViewModel&gt;();
      var clients = new List&lt;ApplicationUser&gt;();
  
      using (var context = new ApplicationDbContext())
      {
          IdentityUserRole role = new IdentityUserRole();
          var tempRole = (from _role in context.Roles
                          where _role.Name == "client"
                          select _role).FirstOrDefault();
          role.Role = tempRole;
  
          clients = (from client in context.Users
                     where client.Email.Contains(criteria.SearchCriteria)
                     || client.FirstName.Contains(criteria.SearchCriteria)
                     || client.MiddleName.Contains(criteria.SearchCriteria)
                     || client.LastName.Contains(criteria.SearchCriteria)
                     || client.SecondLastName.Contains(criteria.SearchCriteria)
                     || client.UserName.Contains(criteria.SearchCriteria)
                     &amp;&amp; client.Roles.Contains(role)
                     select client).ToList();
  
  
      }
  
      foreach (var client in clients)
      {
          results.Add(new SearchResultViewModel()
          {
              Email = client.Email,
              FirstName = client.FirstName,
              MiddleName = client.MiddleName,
              LastName = client.LastName,
              SecondLastName = client.SecondLastName,
              UserName = client.UserName
          });
      }
  
      SearchClientViewModel model = new SearchClientViewModel();
      model.SearchResults = results;
  
      return View("Index", model);
  
  }
  </code></pre>
  
  <p>Linq throws the following Exception</p>
  
  <blockquote>
    <p>An exception of type 'System.NotSupportedException' occurred in
    mscorlib.dll but was not handled in user code</p>
    
    <p>Additional information: Unable to create a constant value of type
    'Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole'. Only
    primitive types or enumeration types are supported in this context.</p>
  </blockquote>
  
  <p>How can this be done, Why the navigation properties is not a collection of Roles, could this be a bug we need to report?</p>