title: Get list of users with assigned roles in asp.net identity 2.0
body: <p>I have a drop down list box which lists roles. I want to get the list of users having that role. I mean list of users that are in "Administrator" role or "CanEdit" role. Here is my code:</p>
  
  <pre><code>public IQueryable&lt;Microsoft.AspNet.Identity.EntityFramework.IdentityUser&gt; 
    GetRolesToUsers([Control] string ddlRole)
  {    
    //ddlRole returns role Id, based on this Id I want to list users
  
    var _db = new ApplicationDbContext();
    IQueryable&lt;Microsoft.AspNet.Identity.EntityFramework.IdentityUser&gt; query = _db.Users;
  
    if (ddlRole != null)
    {
      //query = query.Where(e =&gt; e.Claims == ddlRole.Value);  ???????              
    }
  
    return query;
  }
  </code></pre>
  
  <p>Please help.</p>
  
  <p><strong>Updated Code (still error)</strong></p>
  
  <pre><code>public List&lt;IdentityUserRole&gt; GetRolesToUsers([Control]string ddlRole)
  {
  
    var roleManager = 
     new RoleManager&lt;IdentityRole&gt;(new RoleStore&lt;IdentityRole&gt;(new ApplicationDbContext()));
    var users = roleManager.FindByName("Administrator").Users.ToList();
    return users;
  }
  </code></pre>
  
  <p>Error: The Select Method must return one of "IQueryable" or "IEnumerable" or "Microsoft.AspNet.Identity.EntityFramework.IdentityUser" when ItemType is set to "Microsoft.AspNet.Identity.EntityFramework.IdentityUser".</p>
  
  <p>I tried various castings but none of them helped.</p>
  
  <p><strong>UPDATE (working solution)</strong></p>
  
  <p>Thanks to chris544, his idea helped me to fix this. Here is working method:-</p>
  
  <pre><code>public List&lt;ApplicationUser&gt; GetRolesToUsers([Control]string ddlRole)
  {
    var context = new ApplicationDbContext();
    var users =
      context.Users.Where(x =&gt; x.Roles.Select(y =&gt; y.RoleId).Contains(ddlRole)).ToList();
  
    return users;
  }
  </code></pre>