title: How can I query my join table (many-to-many) using Linq and EF6 (get a users roles)
body: <p>I have 3 tables: <code>Users</code>, <code>UserRoles</code>, <code>UserRoleAssoc</code> (join table consists of only <code>UserID</code> and <code>UserRoleID</code>). Entity Framework does not show <code>UserRoleAssociations</code> in my model which seems correct. My goal is to return a list of the users roles. How do I get all <code>UserRoles</code> where <code>UserID</code>=UserID?</p>
  
  <p>This is what I have does it look correct or is there a better way to do it? I guess I use the Navigation properties that were automatically created when I update model from db?</p>
  
  <pre><code>public IEnumerable&lt;UserRole&gt; GetUserRoles(int userID)
  {
      using (var ctx = new DataEntities())
      {
          var userroles = (from ur in ctx.UserRoles
                           from ura in ur.Users.Where(x =&gt; x.UserID == userID)
                                select ur).ToList();
          return userroles;
      }
  }
  </code></pre>