title: EF Core implementing Table-Per-Concrete-Type with fluent mapping of abstract base class
body: <p>Suppose that you have two entities derived from an abstract base class and you want implement Table-Per-Concrete-Type. Entities like below:</p>
  
  <pre><code>public abstract class EntityBase
  {
     public int Id { get; set; }
  
     public string CreatedBy { get; set; }
  
     public DateTime CreatedAt { get; set; }
  }
  
  public class Person : EntityBase
  {
     public string Name { get; set; }
  }
  public class PersonStatus : EntityBase
  {
     public string Title { get; set; }
  }
  </code></pre>
  
  <p>And you don’t want to use attribute in the abstract base class(EntityBase), you want to map EntityBase class in dbcontext <em>only once</em> for all entities. How to change the code below :</p>
  
  <pre><code>public class PeopleDbContext : DbContext
  {
     public DbSet&lt;Person&gt; People { get; set; }
  
     protected override void OnModelCreating(ModelBuilder modelBuilder)
     {
        base.OnModelCreating(modelBuilder);
  
        // Entity base class mapping(only once)
  
        modelBuilder.Entity&lt;Person&gt;(e =&gt;
        {
          e.Property(x =&gt; x.Name)
              .IsRequired()
              .HasMaxLength(100);
        });
        modelBuilder.Entity&lt;PersonStatus&gt;(e =&gt;
        {
          e.Property(x =&gt; x.Title)
              .IsRequired()
              .HasMaxLength(100);
        });
    }
  
  }
  </code></pre>