title: Mixing TPT and TPC Inheritance in Entity Framework
body: <p>I am trying to apply an entity framework model to an existing database. Each table in the database has a DateCreated and DateModified column, so I have created a base class containing these properties.</p>
  
  <pre><code>public abstract class Entity
  {
      public DateTime DateCreated { get; set; }
      public DateTime DateModified { get; set; }
  }
  </code></pre>
  
  <p>This is table-per-concrete-type inheritance.</p>
  
  <p>I then have an Order table and a SpecialOrder tables that is a specific type of order.</p>
  
  <pre><code>|ORDER|
  |PK_ID|DateCreated|DateModified|
  
  |SPECIALORDER|
  |PK_OrderID|DateCreated|DateModified|
  </code></pre>
  
  <p>Mapped to classes:</p>
  
  <pre><code>public class Order : Entity
  {
      public long Id { get; set; }
  }
  
  public class SpecialOrder : Order
  {
  }
  </code></pre>
  
  <p>This is table-per-type inheritance.</p>
  
  <p>Note: The PK_ID and PK_OrderID columns will have the same value, so I only add an Id property to the Order base class.</p>
  
  <p>My EF configuration for these types:</p>
  
  <pre><code>class OrderConfiguration : EntityTypeConfiguration&lt;Order&gt;
  {
      public OrderConfiguration(string schema)
      {
          ToTable("Order", schema);
          HasKey(x =&gt; x.Id);
          Property(x =&gt; x.Id).HasColumnName(@"PK_ID").HasColumnType("bigint").IsRequired().HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.None);
          Property(x =&gt; x.DateCreated).HasColumnName(@"DateCreated").HasColumnType("datetime").IsRequired();
          Property(x =&gt; x.DateModified).HasColumnName(@"DateModified").HasColumnType("datetime").IsOptional();
      }
  }
  
  class SpecialOrderConfiguration : EntityTypeConfiguration&lt;SpecialOrder&gt;
  {
      public OrderConfiguration(string schema)
      {
          ToTable("SpecialOrder", schema);
          HasKey(x =&gt; x.Id);
          Property(x =&gt; x.Id).HasColumnName(@"PK_OrderID").HasColumnType("bigint").IsRequired().HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.None);
          Property(x =&gt; x.DateCreated).HasColumnName(@"DateCreated").HasColumnType("datetime").IsRequired();
          Property(x =&gt; x.DateModified).HasColumnName(@"DateModified").HasColumnType("datetime").IsOptional();
      }
  }
  </code></pre>
  
  <p>So, I have a single Id property that is mapped to column Order.PK_ID and SpecialOrder.PK_OrderID and when adding an entry to the database, both of these columns are written to using the Order.Id property value.</p>
  
  <p>But, my DateCreated and DateModified values are only written to the columns in the order table and the columns in SpecialOrder are entered NULL.</p>
  
  <p>I can understand why this might not work because although it makes sense on write, when EF reads from the database, which table's DateCreated column would it select to update the one property?</p>
  
  <p>BUT, two columns sharing one property does seem to work fine for Order.PK_ID and SpecialOrder.PK_OrderID.</p>
  
  <p>So, how can I make EF update both DateModified columns from the Entity.DateModified property? And ideally without adding extra DateModified properties to the model classes.</p>