title: EF Core Include multiple inherited types TPH
body: <h2>The problem</h2>
  <p><strong>Query BaseClass and Include information from derived types.</strong></p>
  <p>For example: Base class <strong>Offer</strong> has two types one with a Card only (<strong>CardOffer</strong>) and with Multiple Cards (<strong>CarouselOffer</strong>).</p>
  <p><strong>Question:</strong> How to query the BaseClass and Include the information from the derived types CardOffer and CarouselOffer? In the manner shown below:</p>
  <pre><code>    _dbContext.Offers.Include(...).ToList();
  </code></pre>
  <p>Currently I solved this by querying each inherited type</p>
  <pre><code>        var cards = await _dbContext.CardOffers
              .Include(c =&gt; c.Card)
              .ToListAsync();
  
          var carousels = await _dbContext.CarouselOffers
              .Include(c =&gt; c.Cards)
              .ToListAsync();
          
          List&lt;Offer&gt; offers = new List&lt;Offer&gt;();
          offers.AddRange(cards);
          offers.AddRange(carousels);
  </code></pre>
  <p>But this is far from optimal.</p>
  <p><strong>Additional Information:</strong> Below I added a diagram to show the Database and my code sample:
  <a href="https://i.stack.imgur.com/RWUxF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RWUxF.png" alt="DB Diagram" /></a></p>
  <h2>The Code:</h2>
  <p><strong>Offer</strong> class</p>
  <pre><code>public abstract class Offer
  {
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int ID { get; set; }
  
      public string Status { get; set; }
  
      public string Discrimnator { get; set; }
  
      public ClientUser ClientUser { get; set; }
  }
  </code></pre>
  <p><strong>CardOffer</strong> class:</p>
  <pre><code>public class CardOffer : Offer
  {
      public Card Card { get; set; }
  }
  </code></pre>
  <p><strong>CarouselOffer</strong> class:</p>
  <pre><code>public class CarouselOffer : Offer
  {
      public ICollection&lt;Card&gt; Cards { get; set; }
  }
  </code></pre>
  <p><strong>Card</strong> class:</p>
  <pre><code>public class Card
  {
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int ID { get; set; }
      
      public string Title { get; set; }
      
      public string ImageUrl { get; set; }
      
      public string Description { get; set; }
      
      public string Category { get; set; }
      
      public ICollection&lt;Button&gt; Buttons { get; set; }
  }
  </code></pre>
  <p>FluentApi:</p>
  <pre><code>        modelBuilder.Entity&lt;ClientUser&gt;()
              .HasMany(u =&gt; u.Offers)
              .WithOne(u =&gt; u.ClientUser)
              .OnDelete(DeleteBehavior.Cascade);
          
          modelBuilder.Entity&lt;Offer&gt;()
              .HasDiscriminator&lt;string&gt;(&quot;Discrimnator&quot;);
  
          modelBuilder.Entity&lt;CardOffer&gt;()
              .HasOne(u =&gt; u.Card);
          
          modelBuilder.Entity&lt;CarouselOffer&gt;()
              .HasMany(u =&gt; u.Cards);
  </code></pre>