title: EntityFramework 6 Table per Hierarchy (inheritance)
body: <p>Hi I have a class that has multiple inheritance.
  I wrote this code before EF5 (EF Core 2 or 3) and I just upgraded to EF6 right now.
  Here is the table. I have <code>Entitlement</code> as parent class, and it has many children classes.
  Some class has similiar fields like in <code>AnnualLeaveEntitlement</code> and <code>SickLeaveEntitlement</code>. they are similiar fields but I made separated one.</p>
  <pre><code>using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  using System.ComponentModel.DataAnnotations.Schema;
  
  namespace CRSApp.API.Models
  {
      public class Entitlement
      {
          public int Id { get; set; }      
          [Column(TypeName = &quot;varchar(200)&quot;)] 
          public string Name {get; set;}
          [Column(TypeName=&quot;varchar(200)&quot;)]  
          public string TypeOfLeave {get; set;} 
          public bool isShownOnPaySlip {get; set;}
  
          public string EntitlementType {
          get {
              return this.GetType().Name;
          }
  }
      }
  
      public class AnnualLeaveEntitlement : Entitlement
      {
          public decimal Duration { get; set; }
          [Column(TypeName=&quot;varchar(20)&quot;)]
          public string DurationType { get; set; } // weeks days years hours etc
          public decimal AccrualRate { get; set; } 
  
      }
  
      public class SickLeaveEntitlement : Entitlement
      {
          public decimal Duration { get; set; }
          [Column(TypeName=&quot;varchar(20)&quot;)]
          public string DurationType { get; set; } // weeks days years hours etc
          public decimal AccrualRate { get; set; } 
  
      }
  
      public class LongServiceLeaveEntitlement : Entitlement
      {
          public decimal YearsOfEmployment { get; set; }
          public decimal Duration { get; set; }
          [Column(TypeName=&quot;varchar(20)&quot;)]
          public string DurationType { get; set; } // weeks days years hours etc
          public decimal AccrualRate { get; set; } 
  
      }
  
      public class CompasionateLeaveEntitlement : Entitlement
      {
          public decimal Duration { get; set; }
          [Column(TypeName=&quot;varchar(20)&quot;)]
          public string DurationType { get; set; } // weeks days years hours etc
  
      }
  
      public class JuryDutyLeaveEntitlement : Entitlement
      {
          public string Description {get; set;}
      }
  
      public class StudyLeaveEntitlement : Entitlement
      {
          public decimal Duration { get; set; }
          [Column(TypeName=&quot;varchar(20)&quot;)]
          public string DurationType { get; set; } // weeks days years hours etc
  
      }
  
      public class UnpaidLeaveEntitlement : Entitlement
      {
          public string Description {get; set;}
      }
  
      public class OtherLeaveEntitlement: Entitlement
      {
          public string Description  {get; set;}
      }
  }
  </code></pre>
  <p>Now I generate this table into migrations:</p>
  <pre><code>    migrationBuilder.CreateTable(
          name: &quot;Entitlement&quot;,
          columns: table =&gt; new
          {
              Id = table.Column&lt;int&gt;(type: &quot;int&quot;, nullable: false)
                  .Annotation(&quot;MySql:ValueGenerationStrategy&quot;, MySqlValueGenerationStrategy.IdentityColumn),
              Name = table.Column&lt;string&gt;(type: &quot;varchar(200)&quot;, nullable: true)
                  .Annotation(&quot;MySql:CharSet&quot;, &quot;utf8mb4&quot;),
              TypeOfLeave = table.Column&lt;string&gt;(type: &quot;varchar(200)&quot;, nullable: true)
                  .Annotation(&quot;MySql:CharSet&quot;, &quot;utf8mb4&quot;),
              isShownOnPaySlip = table.Column&lt;bool&gt;(type: &quot;tinyint(1)&quot;, nullable: false),
              Discriminator = table.Column&lt;string&gt;(type: &quot;longtext&quot;, nullable: false)
                  .Annotation(&quot;MySql:CharSet&quot;, &quot;utf8mb4&quot;),
              AnnualLeaveEntitlement_Duration = table.Column&lt;decimal&gt;(type: &quot;decimal(65,30)&quot;, nullable: true),
              AnnualLeaveEntitlement_DurationType = table.Column&lt;string&gt;(type: &quot;varchar(20)&quot;, nullable: true)
                  .Annotation(&quot;MySql:CharSet&quot;, &quot;utf8mb4&quot;),
              AccrualRate = table.Column&lt;decimal&gt;(type: &quot;decimal(65,30)&quot;, nullable: true),
              Duration = table.Column&lt;decimal&gt;(type: &quot;decimal(65,30)&quot;, nullable: true),
              DurationType = table.Column&lt;string&gt;(type: &quot;varchar(20)&quot;, nullable: true)
                  .Annotation(&quot;MySql:CharSet&quot;, &quot;utf8mb4&quot;),
              Description = table.Column&lt;string&gt;(type: &quot;longtext&quot;, nullable: true)
                  .Annotation(&quot;MySql:CharSet&quot;, &quot;utf8mb4&quot;),
              YearsOfEmployment = table.Column&lt;decimal&gt;(type: &quot;decimal(65,30)&quot;, nullable: true),
              LongServiceLeaveEntitlement_Duration = table.Column&lt;decimal&gt;(type: &quot;decimal(65,30)&quot;, nullable: true),
              LongServiceLeaveEntitlement_DurationType = table.Column&lt;string&gt;(type: &quot;varchar(20)&quot;, nullable: true)
                  .Annotation(&quot;MySql:CharSet&quot;, &quot;utf8mb4&quot;),
              LongServiceLeaveEntitlement_AccrualRate = table.Column&lt;decimal&gt;(type: &quot;decimal(65,30)&quot;, nullable: true),
              OtherLeaveEntitlement_Description = table.Column&lt;string&gt;(type: &quot;longtext&quot;, nullable: true)
                  .Annotation(&quot;MySql:CharSet&quot;, &quot;utf8mb4&quot;),
              SickLeaveEntitlement_Duration = table.Column&lt;decimal&gt;(type: &quot;decimal(65,30)&quot;, nullable: true),
              SickLeaveEntitlement_DurationType = table.Column&lt;string&gt;(type: &quot;varchar(20)&quot;, nullable: true)
                  .Annotation(&quot;MySql:CharSet&quot;, &quot;utf8mb4&quot;),
              SickLeaveEntitlement_AccrualRate = table.Column&lt;decimal&gt;(type: &quot;decimal(65,30)&quot;, nullable: true),
              StudyLeaveEntitlement_Duration = table.Column&lt;decimal&gt;(type: &quot;decimal(65,30)&quot;, nullable: true),
              StudyLeaveEntitlement_DurationType = table.Column&lt;string&gt;(type: &quot;varchar(20)&quot;, nullable: true)
                  .Annotation(&quot;MySql:CharSet&quot;, &quot;utf8mb4&quot;),
              UnpaidLeaveEntitlement_Description = table.Column&lt;string&gt;(type: &quot;longtext&quot;, nullable: true)
                  .Annotation(&quot;MySql:CharSet&quot;, &quot;utf8mb4&quot;)
          },
          constraints: table =&gt;
          {
              table.PrimaryKey(&quot;PK_Entitlement&quot;, x =&gt; x.Id);
          })
          .Annotation(&quot;MySql:CharSet&quot;, &quot;utf8mb4&quot;);
  </code></pre>
  <p>But it generated &quot;inconsistent&quot; field, like <code>AnnualLeave</code>, <code>Sickleave</code> they are generated with <code>AnnualLeave_Duration</code> and <code>SickLeave_Duration</code>, but for <code>CompasionatedLeave</code> the migratos just generate <code>Duration</code> and <code>DurationType</code> field</p>
  <p>Does this normal ? Should I migrate to use TPT instead TPH for this case ?</p>
  <p>I also need to query all Entitlements sometimes, how to do that with TPH ?</p>
  <p>Thank you</p>
  <p>note: I use EF Core 6.0.8 and Dotnet 6.0.8. Mysql 8 for database.</p>