title: C# linq to entity include with condition and ordering
body: <p>I have the following (simplified) setup:</p>
  
  <pre><code>Public class parent
  {
      public string name{get;set;}
  
      public list&lt;child&gt; childList {get;set;}
  }
  
  
  Public class child
  {
      public int id {get;set;}
  
      public bool imported{get;set;}
  
      public dateTime? timeSpan {get;set;}
  }
  </code></pre>
  
  <p>and I have this query:</p>
  
  <pre><code>var relevant = context.parent
                  .include(x =&gt; x.child.OrderByDescending(y =&gt; y.id).FirstOrDefaultAsync(z =&gt; z.imported == false &amp;&amp; timeSpan == null)
                  .Where(x =&gt; x.child != null);
  </code></pre>
  
  <p>Which does not work.</p>
  
  <p>Basically, I am trying to include all the parents children, but order them by id descending and then check if the first one (eg newest one) has <code>imported == false</code> and <code>timeSpan == null</code>, and only include the parent rows that have a child that meets this condition.</p>
  
  <p>I know I could do this:</p>
  
  <pre><code>var relevant = context.parent
                  .include(x =&gt; x.child);
  </code></pre>
  
  <p>and then extract the data I need, but is it possible to do it in one using Linq?</p>