title: Linq query w/ sub query and max
body: <p>How do I rewrite this SQL into a Linq query?</p>
  
  <p><strong>Plain SQL</strong></p>
  
  <pre><code>SELECT *
  FROM contracts
      INNER JOIN
          (SELECT contractid, max(date) date 
          FROM contractlogs GROUP BY contractId) b 
      ON contracts.id = b.contractId
  </code></pre>
  
  <p><strong>Attempt at Linq</strong></p>
  
  <pre><code>from c in _db.Contracts
  join sub in (from cl in _db.ContractLogs
               group cl by cl.contractId into g
               select new { contractId = g.contractId, changedate = g.Max(x =&gt; x.date)})
      on c.id equals sub.contractId 
  select new { c, cl }
  </code></pre>
  
  <p>Goal of the query is to select all contracts w/ their newest update (first) (in contractLogs). I'm currently stumped on how the select would work. Ideally i'm trying to return an object with c &amp; cl.</p>