title: Linq Query with join on subquery
body: <p>Basically I'm trying to write a query where it joins on select top 1 from a second table so something like:</p>
  
  <pre><code>SELECT Sum(pinfo.quantity + p.itemcount), 
     i.owner 
  FROM   invoice i 
     JOIN purchase_info pinfo 
       ON pinfo.invoice = i.invid 
     JOIN (SELECT DISTINCT sku, 
                           productlineid, 
                           itemcount 
           FROM   products WHERE productlineid in (13, 14)) p 
       ON p.sku = pinfo.item 
  WHERE i.owner = 22623 
  GROUP BY i.owner
  </code></pre>
  
  <p>Here's my pathetic attempt in linq that has somewhat invalid syntax, any ideas would be much appreciated.</p>
  
  <pre><code>(from i in _invoiceRepository.Table
   join pi in _purchaseInfoRepository.Table on i.InvoiceId equals pi.InvoiceId
   join p in (from p2 in _productRepository.Table where p2.Sku == pi.Item select new { p2.Sku, p2.ItemCount }).Take(1)
   on pi.Item equals p.Sku
  
   where i.MemberId == memberId &amp;&amp;
   (p.ProductLineId == (int)ProductLines.InkCartridges ||
    p.ProductLineId == (int)ProductLines.TonerCartridges)
   select pi.Quantity * p.ItemCount)
  .DefaultIfEmpty(0)
  .Sum();
  </code></pre>