title: In Entity Framework Core, with one query, how do I select objects by the order of a parent object?
body: <p>I'm working in Entity Framework Core 2.0, and I'm trying to do something like this. I want a list of all the classes taught by the oldest teacher. I tried to make the two requests into one query, but I couldn't make it work. Is there a concise way to make this one query?</p>
  
  <pre><code>private async Task&lt;Teacher&gt; GetOldestTeacher(int schoolId)
  {
      using (var db = new SchoolContext())
      {
          return await db.Teacher
              .Where(t =&gt; t.SchoolId == schoolId)
              .OrderByDescending(t =&gt; t.DateOfBirth)
              .FirstAsync();
      }
  }
  
  public async Task&lt;IEnumerable&lt;Class&gt;&gt; GetOldestTeachersClasses(int schoolId)
  {
      var oldestTeacher = await GetOldestTeacher(schoolId);
      using (var db = new SchoolContext())
      {
          return await db.Class
              .Where(c =&gt; c.TeacherId == oldestTeacher.Id &amp;&amp; c.SchoolId == schoolId)
              .ToListAsync();
      }
  }
  </code></pre>
  
  <p>This isn't exactly my code, but it's close enough to what I'm shooting for. This works, but I'm looking to make it more efficient. Any help would be appreciated.</p>