title: Filtering included object with OfType<T> for specific ThenInclude by type T
body: <p>Considering the classes :</p>
  
  <pre><code>public class MainObject
  {
      List&lt;Base&gt; myList;
  }
  public class Base
  {
      int MainObjectId;
      int x;
  }
  public class A : Base
  {
      int y;
  }
  public class B : Base
  {
      int z;
      AnotherObject anotherObject;
  }
  </code></pre>
  
  <p>With such a configuration i want to include different things depending on the type of the elements in MainObject.myList</p>
  
  <p>I tried something like that :</p>
  
  <pre><code>var result = context.mainObjects
                      .Include(mo =&gt; mo.myList.OfType&lt;A&gt;())
                      .Include(mo =&gt; mo.myList.OfType&lt;B&gt;()).ThenInclude(b =&gt; b.anotherObject)
                      .Where (mo =&gt; mo.Id == paramId)
                      .FirstOrDefault();
  </code></pre>
  
  <p>Then i tried with 2 distinct queries :</p>
  
  <pre><code>var resultForA = context.mainObjects
                  .Include(mo =&gt; mo.myList.OfType&lt;A&gt;())
                  ..Where(mo =&gt; mo.Id == paramId)
                  .FirstOrDefault();
  
  var resultForB = context.mainObjects
                  .Include(mo =&gt; mo.myList.OfType&lt;B&gt;()).ThenInclude(b =&gt; b.anotherObject)
                  ..Where(mo =&gt; mo.Id == paramId)
                  .FirstOrDefault();
  </code></pre>
  
  <p>None of it works. </p>
  
  <p>Is there a way to filter included object with OfType to have specific sub inclusion based on the type  ?</p>
  
  <p><strong>EDIT</strong> : i already solved the issue by doing something like this</p>
  
  <pre><code>var ListOfA = context.BaseObjects
                 .OfType&lt;A&gt;()
                 .Where(a =&gt; a.MainObjectId == id)
                 .ToList();
  
  var ListOfB = context.BaseObjects.Include(b =&gt; b.anotherObject)
                 .OfType&lt;B&gt;()
                 .Where(b =&gt; b.MainObjectId == id)
                 .ToList();
  </code></pre>
  
  <p>But i still wonder if there is a way to do it in one query ? Or 2 but starting with MainObject ?</p>