title: Unable to create a constant value of type 'IdentityUserRole'. Only primitive types or enumeration types are supported
body: <p>In my ASP.NET MVC 5 application I want to list the roles of a user. I downloaded some samples that seem to be broken. Basically I want both the role ID and role name of the roles of a selected user (not the current user!).</p>
  
  <p>ApplicationUser.Roles gives me an IdentityUserRole object with only RoleId and UserId.</p>
  
  <p>ApplicationDbContext.Roles gives me an IdentityRole with RoleId, RoleName etc. of ALL application roles.</p>
  
  <p>So what I want is a result set with the intersection of both sets while retaining full role information so that I can use both its role ID and role name.</p>
  
  <p>I tried Intersect() but that didn't work because both objects are of different type. I tried the dumb style of iterating but got an exception saying the DAta Reader was already active so I am stumped :(</p>
  
  <p>I tried the following on LinQPad (with the appropriate conenctions and namespaces):</p>
  
  <pre><code>string UserName = "user@email.com";
  ApplicationDbContext ctx = new ApplicationDbContext();
  var allroles = ctx.Roles.OrderBy(r =&gt; r.Id);
  allroles.Dump();    // dumps well, 6 roles
  
  ApplicationUser user = ctx.Users.Where(u =&gt; u.UserName.Equals(UserName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
  var myroles = user.Roles;
  myroles.Dump();     // dumps well, 3 roles
  
  IEnumerable&lt;IdentityRole&gt; list = from roles in allroles
      join uroles in myroles
      on roles.Id equals uroles.RoleId
      select roles;
  list.Dump();    // exception
  </code></pre>
  
  <p>And while the query seems to produce no error during execution, its dumping does regardless of whether I use Dump() or an explicit foreach (IdentityRole item in list). The error I get in this case is</p>
  
  <p>"Unable to reate a constant value of type 'Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole'. Only primitive types or enumeration types are supported in this context".</p>