title: Inherit a common base class in EF code first
body: <p>I'm converting my EF POCO project to Code first. I had changed the T4 template, so that all my entities use a base class, <code>EntityBase</code>, that provides them with some common functionality that is not persistence related.</p>
  
  <p>If I use <code>[NotMapped]</code> attribute on <code>EntityBase</code>, all entities inherit this attribute and I get a <code>The type 'X.X.Person' was not mapped</code>, for any type I try to use with EF.</p>
  
  <p>If I use <code>[NotMapped]</code> on all properties of <code>EntityBase</code>, I get a <code>EntityType 'EntityBase' has no key defined. Define the key for this EntityType</code> exception</p>
  
  <p>FYI: I use Ef 4.3.1</p>
  
  <p>Edit: part of the code:</p>
  
  <pre><code>[DataContract(IsReference = true)]
  public abstract class EntityBase : INotifyPropertyChanged, INotifyPropertyChanging
  {
      [NotMapped]
      public virtual int? Key
      {
          get { return GetKeyExtractor(ConversionHelper.GetEntityType(this))(this); }
      }
      //other properties and methods!
  }
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>[DataContract(IsReference = true), Table("Person", Schema = "PER")]
  public abstract partial class Person : BaseClasses.EntityBase, ISelfInitializer
  {
      #region Primitive Properties
      private int? _personID;
      [DataMember,Key]
      public virtual int? PersonID
      {
          get{ return _personID; }
          set{ SetPropertyValue&lt;int?&gt;(ref _personID, value, "PersonID"); }
      }
  }
  </code></pre>
  
  <p>For these two classes there is not fluent api configuration.</p>