title: Linq FirstOrDefault returning multiple
body: <p>I am having a strange issue in which a linq statement is returning multiple entities even though it has <code>.FirstOrDefault()</code>.</p>
  
  <pre><code>var endlog = from e in endLogs
               where e.user_id == log.user_id &amp;&amp; e.end_time &lt;= log.start_time
               group e by e.end_time into g
               select g.OrderByDescending(x =&gt; x.end_time).FirstOrDefault();
  
  user_state_log eLog = endlog.SingleOrDefault();
  </code></pre>
  
  <p>What this is doing is selecting the log with the most recent end time compared to the supplied <code>log</code>.
  I get an exception on <code>user_state_log eLog = endlog.SingleOrDefault()</code> stating that there is more than one entity in the variable. Any ideas?</p>