title: EF: Subclass with no table one-to-many
body: <p>I have the following scenario:</p>
  
  <ul>
  <li>A base class mapped to the database, which has several derived classes, some with their own table some not (they don't add properties).</li>
  <li>A derived class with no table that only has a collection of the third class (this one adds a property but has no table since it's only a relationship).</li>
  <li><p>A third class which has a foreign key to the base class table.</p>
  
  <pre><code>public class BaseEntity
  {
      public short Id {get;set;}
      //Other Properties
  }
  
  [NotMapped]
  public class DerivedEntity : BaseEntity
  {
      public virtual ICollection&lt;Message&gt; Messages {get;set;}
  }
  
  public class Message
  {
      public short Id {get;set;}
      public short DerivedEntityId {get;set;}
      public virtual DerivedEntity DerivedEntity {get;set;}
      //Other Properties
  }
  </code></pre></li>
  </ul>
  
  <p>The schema:</p>
  
  <pre><code>Table BaseEntity(
      Id smallint PK,
      --Other Columns
  )
  
  Table Message(
      Id smallint PK,
      DerivedEntityId smallint FK,
      --Other Columns
  )
  </code></pre>
  
  <p>And finally the mappings:</p>
  
  <pre><code>public BaseEntityMap(){
      ToTable(...);
      HasKey(x =&gt; x.Id);
      //Other Properties and Relationships
  }
  
  public MessaeMap(){
      ToTable(...);
      HasKey(x =&gt; x.Id);
  
      //This is the important part
      HasRequired(m =&gt; m.DerivedEntity)
          .WithMany(de =&gt; de.Messages)
          .HasForeignKey(m =&gt; m.DerivedEntityId);
  }
  </code></pre>
  
  <p>Note that there is no map for DerivedEntity.</p>
  
  <p>When EF validates the model against the DB it throws the following exception:</p>
  
  <blockquote>
    <p>The navigation property 'DerivedEntity' is not a declared property on type 'Message'. Verify that it has not been explicitly exluded from the model and that it is a valid navigation property.</p>
  </blockquote>
  
  <p>I have already googled the exception but in general they were because some mappings were missing, or some typos in the FK, etc.</p>
  
  <p>I can do some workaround to manually attach the messages to the correspondent DerivedEntity, but that may require two trips to the DB. Does EF have a way for handling these situations??</p>
  
  <p>I am using EF 6 and SQL SERVER 2012.</p>