title: How do I join 2 dbSets in a repository relationship request using Linq / Entity framework
body: <p>Let's say I have the following code:</p>
  
  <pre><code>    public ActionResult ListByJames(int jamesID, int page = 1, string sort = "Name", bool desc = false)
      {
          IEnumerable&lt;Bob&gt; orderedBobs = bobRepository.SortByColumnName(sort, desc);
          IEnumerable&lt;Bob_JamesRelationship&gt; bobRelations = bobRelationshipRepository.Relationships;
          James james = jamesRepository.GetByID(jamesID);
  
          // At the moment, the following returning model just returns a 
          // list of Bobs, but I need to return a list of bobs that are 
          // related to the James that is passed through
  
          ListViewModel&lt;Bob&gt; model = new ListViewModel&lt;Bob&gt;
          {
              Items = orderedBobs
                  .Skip((page - 1) * PageSize)
                  .Take(PageSize),
              PagingInfo = new PagingInfo
              {
                  CurrentPage = page,
                  ItemsPerPage = PageSize,
                  TotalItems = orderedBobs.Count(),
                  Sort = sort,
                  Desc = desc
              }
          };
          return View("_List", model);
      }
  </code></pre>
  
  <p>I need to make a SQL statement like this:</p>
  
  <pre><code>SELECT
      *
  FROM 
      James j
  JOIN
      Bob_JamesRelationships r ON
      j.Id = r.JamesID
  JOIN
      Bobs b ON
      b.Id = r.BobID
  </code></pre>
  
  <p>but in the style of my C# code using Linq</p>
  
  <p>Note that the following lines</p>
  
  <pre><code>        IEnumerable&lt;Bob&gt; orderedBobs = bobRepository.SortByColumnName(sort, desc);
          IEnumerable&lt;Bob_JamesRelationship&gt; bobRelations = bobRelationshipRepository.Relationships;
          James james = jamesRepository.GetByID(jamesID);
  </code></pre>
  
  <p>contain all of the information required to get the required set of Bobs back. </p>
  
  <p>A James is related to a Bob via a Bob_JamesRelationship... I also have 3 SQL tables that represent these too.</p>
  
  <p>How do I go about doing this?</p>