title: Entity framework Fluent API does not consider base class properties
body: <p>EF 6.1 :</p>
  
  <p>We just started a project that has a lot pf inheritance. The selected inheritance db mapping type is the table per hierarchy. The problem is that when trying to generate the migration using the add-migration, the following error is thrown : </p>
  
  <pre><code>The foreign key component 'VersionId' is not a declared property on type 'SER'. Verify that it has not been explicitly excluded from the model and that it is a valid primitive property.
  </code></pre>
  
  <p>Here are the classes &amp; the configuration classes used :</p>
  
  <pre><code>public class Version : BaseObject
  {
      public virtual ICollection&lt;SER&gt; ListOfSER { get; set; }
  }
  
  public abstract class AbsractR : BaseObject
  {
      public int ParentId { get; set; }
      public int ChildId { get; set; }
  
      public int VersionId { get; set; }
      public virtual Version Version { get; set; }
  }
  
  public class SER : AbstractR
  {
      public int SEDId
      {
          get
          {
              return base.ChildId;
          }
          set
          {
              base.ChildId = value;
          }
      }
      public virtual SED SED { get; set; }
  }
  
  public abstract class AbstractD : BaseObject
  {
  }
  
  public class SED : AbstractD
  {
      public virtual ICollection&lt;SER&gt; ListOfSER { get; set; }
  }
  
  
  public class SDContext : BaseContext
  {
      public DbSet&lt;Version&gt; Versions { get; set; }
      public DbSet&lt;AbstractD&gt; Ds { get; set; }
      public DbSet&lt;AbstractR&gt; Rs { get; set; }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          base.OnModelCreating(modelBuilder);
          modelBuilder.Configurations.Add(new VersionConfiguration());
  
          #region Refs
          modelBuilder.Configurations.Add(new AbstractRConfiguration());
          modelBuilder.Configurations.Add(new SERConfiguration());
          #endregion
  
          #region Defs
          modelBuilder.Configurations.Add(new AbstractDConfiguration());
          modelBuilder.Configurations.Add(new SEDConfiguration());
          #endregion
      }
  }
  
  public class BaseObjectConfiguration&lt;T&gt; : EntityTypeConfiguration&lt;T&gt; where T : BaseObject
  {
      public BaseObjectConfiguration()
      {
          #region Key
          this.HasKey(bo =&gt; bo.Id);
          #endregion
  
          #region Properties
          this.Property(bo =&gt; bo.Id).IsRequired();
          this.Property(bo =&gt; bo.IsDeleted).IsRequired();
          this.Property(bo =&gt; bo.LastModificationDate).IsOptional();
          this.Property(bo =&gt; bo.OptimisticVersion).IsConcurrencyToken().IsRequired().IsRowVersion();
          this.Property(bo =&gt; bo.CreationDate).IsRequired();
          this.Property(bo =&gt; bo.DeletionDate).IsOptional();
          #endregion
      }
  }
  
  public class VersionConfiguration : BaseObjectConfiguration&lt;Version&gt;
  {
      public VersionConfiguration() : base()
      {
          #region Properties
          #endregion
  
          #region Objects
          this.HasMany(mdv =&gt; mdv.ListOfSER).WithRequired().HasForeignKey(ser =&gt; ser.VersionId).WillCascadeOnDelete(false);
          #endregion
  
          #region Table
          this.ToTable("Versions");
          #endregion
      }
  }
  
  public class AbstractRConfiguration : BaseObjectConfiguration&lt;AbstractR&gt;
  {
      public AbstractRConfiguration()
          : base()
      {
          #region Properties
          this.Property(ser =&gt; ser.VersionId).IsRequired();
          #endregion
  
          #region Objects
          this.HasRequired(ar =&gt; ar.Version).WithMany().HasForeignKey(ar =&gt; ar.VersionId).WillCascadeOnDelete(false);
          #endregion
  
          #region Table
          this.ToTable("Refs");
          #endregion
      }
  }
  
  public class SERConfiguration : BaseObjectConfiguration&lt;SER&gt;
  {
      public SERConfiguration()
          : base()
      {
          #region Properties
          this.Ignore(ser =&gt; ser.SEDId);
          #endregion
  
          #region Objects
          this.HasRequired(ser =&gt; ser.SED).WithMany(sed =&gt; sed.ListOfSER).HasForeignKey(ser =&gt; ser.ChildId).WillCascadeOnDelete(false);
          #endregion
  
          #region Table
          this.ToTable("Refs");
          #endregion
      }
  }
  
  public class AbstractDConfiguration : BaseObjectConfiguration&lt;AbstractD&gt;
  {
      public AbstractDConfiguration() : base()
      {
          this.ToTable("Defs");
      }
  }
  
  public class SEDConfiguration : BaseObjectConfiguration&lt;SED&gt;
  {
      public SEDConfiguration()
          : base()
      {
          #region Properties
          #endregion
  
          #region Objects
          this.HasMany(sed =&gt; sed.ListOfSER).WithRequired(sed =&gt; sed.SED).HasForeignKey(sed =&gt; sed.ChildId).WillCascadeOnDelete(false);
          #endregion
  
          #region Table
          this.ToTable("Defs");
          #endregion
      }
  }
  </code></pre>
  
  <p>I know we can use the [ForeignKey] attribute to tell that the navigation property on a derived class should use the column defined in the parent abstract class. We would like to avoid using DataAnnotations. I just don't get why it throw this error. The "Version" navigation property is defined in the AbstractR configuration and not in the SER configuration (which should also work since SER inherits from AbstractR), am I right ?</p>
  
  <p>Secondly, when removing the Version property &amp; mapping, the same problem appears with the "ChildId" and "ParentId" property used in the SER mapping. Is this a know problem ? Am I doing something wrong ?</p>
  
  <p>PS : The ParentId mapping has been removed for simplicity since it seems to be the same problem as the ChildId mapping.</p>
  
  <p>Has anyone any idea why this kind of problem is happening ?</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After some more research, it appeared that Fluent API cannot use base class properties for the mapping. Is that right ? Is this a wanted behavior ? Why are the DataAnnotations able to use base class properties and not Fluent API ? Aren't all the base class properties inserted inside every classes or is it read with some kind of decorator pattern ?</p>