title: How to do join with objects in Entity Framework
body: <p>So I am converting a old project with ordinary SQL queries to a ORM using the Entity Framework. So I have created database model like this:</p>
  
  <p><img src="https://i.stack.imgur.com/pi8E6.png" alt="Database model"></p>
  
  <p>So I had this old query which I want to translate to a linq expression</p>
  
  <pre><code>SELECT UGLINK.USERNAME 
  FROM GMLINK 
  INNER JOIN UGLINK 
  ON GMLINK.GROUPID = UGLINK.GROUPID 
  WHERE (((GMLINK.MODULEID)=%ID%))
  </code></pre>
  
  <p>And the problem I have is that I can't figure out how to do a join query using the objects.
  Instead I have to go though the properties like this (which seems to be working):</p>
  
  <pre><code>// So this is one of the module objects that is located in a listView in the GUI
  Module m = ModuleList.selectedItem as Module;
  
  /* Now I want to fetch all the User objects that, 
   * via a group, is connected to a certain module */
  var query = context.gmLink
      .Join(context.ugLink,
            gmlink =&gt; gmlink.GroupId,
            uglink =&gt; uglink.GroupId,
            (gmlink, uglink) =&gt; new { gmLink = gmlink, ugLink = uglink })
      .Where(gmlink =&gt; gmlink.gmLink.ModuleId == m.ModuleId)
      .Select(x =&gt; x.ugLink.User);
  </code></pre>
  
  <p>So as I said this works, but as you see I kind of have to connect the modules via the link tables properties <code>.GroupId</code> and <code>.ModuleId</code> and so on. Instead I would like to go through the objects created by EF.</p>
  
  <p>I wanted to write a question a bit like this, but can't figure out how to do it, is it at all possible?</p>
  
  <pre><code>var query = context.User
              .Select(u =&gt; u.ugLink
                  .Select(uglink =&gt; uglink.Group.gmLink
                      .Where(gmLink =&gt; gmLink.Module == m)));
  </code></pre>