title: LINQ - get parent based on last child condition
body: <p>I have the current entities: </p>
  
  <p><strong>Students (Id, Name,..)</strong> </p>
  
  <p><strong>Grades (Id, Student_Id, Grade)</strong> </p>
  
  <p>A student can have more of no grades.. </p>
  
  <p>Using LINQ (Entity Framework) how can I get a list of all students that have the last grade different than 10! </p>
  
  <p>I was trying: </p>
  
  <pre><code>var students = db.students.Where(c =&gt; c.Grades.LastOrDefault().Grade != 10) .ToList(); 
  </code></pre>
  
  <p>The problem is since I may not have any grades, the <code>LastOrDefault</code> can be <code>null</code>. </p>