title: EF Core base entity class inheritance and readonly properties
body: <p>Is it possible to do something like this:</p>
  
  <pre><code>public abstract class BaseEntity : IEntity
  {
      private Guid _id;
      private DateTime _createdOn;
      private DateTime _modifiedOn;
      private byte[] _timestamp;
  
      [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public Guid Id =&gt; _id;
  
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public DateTime CreatedOn =&gt; _createdOn;
  
      [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
      public DateTime ModifiedOn =&gt; _modifiedOn;
  
      [Timestamp]
      public byte[] Timestamp =&gt; _timestamp;
  }
  </code></pre>
  
  <p>This is base class, all entities should inherit from this class. Also this properties should be readonly (I'm using <a href="http://ef.readthedocs.io/en/latest/modeling/backing-field.html" rel="nofollow">backing properties</a>), because EF need to take care of them.</p>
  
  <pre><code>public class Category : BaseEntity
  {
      [Required]
      public string Name { get; set; }
  
      public string Description { get; set; }
  }
  </code></pre>
  
  <p>And <code>OnModelCreating</code> is empty.
  When I run migrations, I get message : </p>
  
  <blockquote>
    <p>'The entity type 'Project.Database.Models.Category' requires a primary
    key to be defined.</p>
  </blockquote>