title: Use fluent to configure EF Core properties on entities of a certain type
body: <p>I have a bunch of entities which I want to have fields <code>InsertDate</code> and <code>UpdateDate</code>, with (SQL) default values of <code>GETDATE()</code>.</p>
  <p>To that end, I made a simple class <code>AuditableEntity</code> which a bunch of my entities derived from that looks basically like this:</p>
  <pre><code>public class AuditableEntity
  {
      InsertDate { get; set; }
      UpdateDate { get; set; }
  }
  </code></pre>
  <p>and sample entity like</p>
  <pre><code>public class Customer : AuditableEntity
  {
      CustomerId int { get; set; }
      // etc..
  }
  </code></pre>
  <p>Then when I'm configuring the entities using the fluent API, I can do something like:</p>
  <pre><code>public class CustomerConfiguration : IEntityTypeConfiguration&lt;Customer&gt;
  {
      public void Configure(EntityTypeBuilder&lt;Customer&gt; builder)
      {
          builder.Property(e =&gt; e.InsertDate)
              .HasDefaultValueSql(&quot;getdate()&quot;);
          builder.Property(e =&gt; e.UpdateDate)
              .HasDefaultValueSql(&quot;getdate()&quot;);
      }
  }
  </code></pre>
  <p>So far, so good.</p>
  <p>Except I have a bunch of these <code>AuditableEntities</code>, each of which needs those same two property definitions set up.</p>
  <p>Is there some central place I can build properties for all Entity which are subtypes of <code>AuditableEntity</code>? I tried something like the following, but it fails because it looks like it's trying to instantiate a <code>DbSet&lt;AuditableEntity&gt;</code> when all I want to do is to add an identical property to all entities of type <code>AuditableEntity</code>.</p>
  <pre><code>protected override void OnModelCreating(ModelBuilder modelBuilder)
  {
      modelBuilder.Entity&lt;AuditableEntity&gt;(entity =&gt;
          {
              entity.Property(e =&gt; e.InsertDate)
                  .HasDefaultValueSql(&quot;getdate()&quot;);
              entity.Property(e =&gt; e.UpdateDate)
                  .HasDefaultValueSql(&quot;getdate()&quot;);
          });
      modelBuilder.ApplyConfigurationsFromAssembly(typeof(MyContext).Assembly);
      }
      /* When I try to run add-migration with this in here, it says:
       * system.InvalidOperationException: A key cannot be configured on 'DatasetSource' because it is a derived type. The key must be configured on the root type 'AuditableEntity'. If you did not intend for 'AuditableEntity' to be included in the model, ensure that it is not referenced by a DbSet property on your context, referenced in a configuration call to ModelBuilder, or referenced from a navigation on a type that is included in the model.
       */
  </code></pre>