title: Entity Framework 4 - What is the syntax for joining 2 tables then paging them?
body: <p>I have the following linq-to-entities query with 2 joined tables that I would like to add pagination to:</p>
  
  <pre><code>IQueryable&lt;ProductInventory&gt; data = from inventory in objContext.ProductInventory
      join variant in objContext.Variants
          on inventory.VariantId equals variant.id
       where inventory.ProductId == productId
       where inventory.StoreId == storeId
       orderby variant.SortOrder
       select inventory;
  </code></pre>
  
  <p>I realize I need to use the .Join() extension method and then call .OrderBy().Skip().Take() to do this, I am just gettting tripped up on the syntax of Join() and can't seem to find any examples (either online or in books).</p>
  
  <p><strong>NOTE:</strong> The reason I am joining the tables is to do the sorting. If there is a better way to sort based on a value in a related table than join, please include it in your answer.</p>
  
  <p><strong>2 Possible Solutions</strong></p>
  
  <p>I guess this one is just a matter of readability, but both of these will work and are semantically identical.</p>
  
  <h1>1</h1>
  
  <pre><code>IQueryable&lt;ProductInventory&gt; data = objContext.ProductInventory
                  .Where(y =&gt; y.ProductId == productId)
                  .Where(y =&gt; y.StoreId == storeId)
                  .Join(objContext.Variants,
                      pi =&gt; pi.VariantId,
                      v =&gt; v.id,
                      (pi, v) =&gt; new { Inventory = pi, Variant = v })
                  .OrderBy(y =&gt; y.Variant.SortOrder)
                  .Skip(skip)
                  .Take(take)
                  .Select(x =&gt; x.Inventory);
  </code></pre>
  
  <h1>2</h1>
  
  <pre><code>var query = from inventory in objContext.ProductInventory
      where inventory.ProductId == productId
      where inventory.StoreId == storeId
      join variant in objContext.Variants
          on inventory.VariantId equals variant.id
      orderby variant.SortOrder
      select inventory;
  
  var paged = query.Skip(skip).Take(take);
  </code></pre>
  
  <p>Kudos to Khumesh and Pravin for helping with this. Thanks to the rest for contributing.</p>