title: EF Conditional Include by Entity Type
body: <p>Please, suppose that architecture:</p>
  
  <pre><code>public class Mammal
  {
      public int Id { get; set; }
      public string Name { get; set; }
  }
  
  public class Dog : Mammal
  {
      public int TailId { get; set; }
      public Tail Tail { get; set; }
  }
  
  public class Bat : Mammal
  {
      public int WingId { get; set; }
      public Wing Wing { get; set; }
  }
  
  public class Buffalo : Mammal
  {
      public virtual ICollection&lt;Horn&gt; Horns { get; set; }
  }
  
  public class Tail
  {
      public int Id { get; set; }
      ...
  }
  
  public class Wing
  {
      public int Id { get; set; }
      ...
  }
  
  public class Horn
  {
      public int Id { get; set; }
      ...
  }
  </code></pre>
  
  <p>Now, my context:</p>
  
  <pre><code>public class MyContext : DbContext
  {
      public DbSet&lt;Mammal&gt; Mammals { get; set; }
  }
  </code></pre>
  
  <p>So, I want to make ONLY ONE sql query, and include (and load) all nested entities, something like:</p>
  
  <pre><code>var query = myContext.Mammals
      .IncludeIfTypeIs&lt;Dog&gt;(d =&gt; d.Tail)
      .IncludeIfTypeIs&lt;Bat&gt;(b =&gt; b.Wing)
      .IncludeIfTypeIs&lt;Buffalo&gt;(b =&gt; b.Horns)
      ...
      ...
  ;
  </code></pre>
  
  <p>I know that I can do that separately, but I don't want because I have many entities, and I need to minimize database requests.</p>
  
  <p>I don't want use lazy loading because this will make many database requests also.</p>
  
  <p>How to achieve that?</p>