title: Linq with subquery with Let
body: <p>What I'm trying to get from this Linq query is a list of all Adverts where the most recent associated Log with a <code>LogType.IsStatus == true</code> has a <code>LogType.Name</code> of either Confirmed or Renewed. To be clear, an Advert has many Logs and each Log has one LogType. So far I have the following, but it's giving me an error System.NotSupportedException on the LastOrDefault.</p>
  
  <pre><code>var adverts = (from a in database.Adverts
                        let lastLog = (from l in a.Logs
                                       where l.LogType.IsStatus == true
                                       orderby l.Created_at
                                       select l).LastOrDefault()
                        where (lastLog != null)
                              &amp;&amp;
                              (lastLog.LogType.Name == "Confirmed" || lastLog.LogType.Name == "Renewed")
                              orderby a.Created_at descending
                        select a).ToList();
  </code></pre>