title: Including derived child properties in Entity Framework Core 2.0
body: <p>Using Entity Framework Core 2.0, I am trying to construct a query to include related data for a polymorphic child entity.</p>
  
  <p>For example, given the following types:</p>
  
  <pre><code>    public class ParentEntity
      {
          public int Id { get; set; }
  
          public IList&lt;ChildEntityBase&gt; Children { get; set; }
      }
  
      public abstract class ChildEntityBase
      {
          public int Id { get; set; }
      }
  
      public class ChildEntityA : ChildEntityBase
      {
      }
  
      public class ChildEntityB : ChildEntityBase
      {
          public IList&lt;GrandchildEntity&gt; Children { get; set; }
      }
  
      public class GrandchildEntity
      {
          public int Id { get; set; }
  
      }
  </code></pre>
  
  <p>and the following configuration:</p>
  
  <pre><code>    public DbSet&lt;ParentEntity&gt; ParentEntities { get; set; }
  
      protected override void OnModelCreating(ModelBuilder builder)
      {
          builder.Entity&lt;ParentEntity&gt;().HasKey(p =&gt; p.Id);
          builder.Entity&lt;ParentEntity&gt;().HasMany(p =&gt; p.Children).WithOne();
  
          builder.Entity&lt;ChildEntityBase&gt;().HasKey(c =&gt; c.Id);
          builder.Entity&lt;ChildEntityBase&gt;()
              .HasDiscriminator&lt;string&gt;("ChildEntityType")
              .HasValue&lt;ChildEntityA&gt;("a")
              .HasValue&lt;ChildEntityB&gt;("b");
  
          builder.Entity&lt;ChildEntityA&gt;()
              .HasBaseType&lt;ChildEntityBase&gt;();
  
          builder.Entity&lt;ChildEntityB&gt;()
              .HasBaseType&lt;ChildEntityBase&gt;()
              .HasMany(u =&gt; u.Children).WithOne();
  
          builder.Entity&lt;GrandchildEntity&gt;()
              .HasBaseType&lt;ChildEntityBase&gt;();
  
          base.OnModelCreating(builder);
      }
  </code></pre>
  
  <p>I am trying to write the following query:</p>
  
  <pre><code>        var result = this.serviceDbContext.ParentEntities
              .Include(p =&gt; p.Children)
              .ThenInclude((ChildEntityB b) =&gt; b.Children);
  </code></pre>
  
  <p>Unfortunately, this is resulting in a syntax error.</p>
  
  <p>However, I believe I am following the syntax as specified in <a href="https://github.com/aspnet/EntityFrameworkCore/commit/07afd7aa330da5b6d90d518da7375d8bbf676dfd" rel="noreferrer">https://github.com/aspnet/EntityFrameworkCore/commit/07afd7aa330da5b6d90d518da7375d8bbf676dfd</a></p>
  
  <p>Can anyone suggest what I'm doing wrong?</p>
  
  <p>Thanks</p>