title: LINQ check if FirstOrDefault is null and use it
body: <p>I'm writing a query that uses <code>FirstOrDefault</code> after an <code>OrderBy</code> query, which should check if it isn't null first then use some data in it. Is there a better way than writing it like this:</p>
  
  <pre><code>int count = db.Items.Count(i =&gt; 
            i.Assignments.OrderByDescending(a =&gt; 
                  a.DateAssigned).FirstOrDefault() != null
            &amp;&amp; 
            i.Assignments.OrderByDescending(a =&gt;
                  a.DateAssigned).FirstOrDefault().DateReturned == null)
  </code></pre>
  
  <p>What this code does is there are items that has many assignments, I take the latest assignment by date, then check if it exist, then run a condition on a property (<code>DateReturned</code>). As you see, this query is long, and most of my queries seem to look like this where I check for null first then run a second query on it using their properties. Is there a better way of doing this?</p>