title: EF Inheritance and Foreign Keys
body: <p>I'm going for TPH inheritance here - one Comments table with a discriminator.  </p>
  
  <p>I keep getting the error: </p>
  
  <blockquote>
    <p>The foreign key component 'ResponseId' is not a declared property on
    type 'PostComment'. Verify that it has not been explicitly excluded
    from the model and that it is a valid primitive property.</p>
  </blockquote>
  
  <p>Whenever I try to perform a fresh migration.</p>
  
  <p>Models: </p>
  
  <pre><code>public class Comment : Message {
      [Key]
      [Required]
      public int CommentId { get; set; }
      [Required]
      public int ResponseId { get; set; }
  }
  
  public class PostComment : Comment {
      public virtual PostResponse PostResponse { get; set; }
  }
  public class FlagComment : Comment {
      public virtual FlagResponse FlagResponse { get; set; }
  }
  </code></pre>
  
  <p>Mappings: </p>
  
  <pre><code>public class CommentConfiguration : EntityTypeConfiguration&lt;Comment&gt; {
      public CommentConfiguration() {
          // Comment has Poster (From Message base class)
          HasRequired(c =&gt; c.Poster)
          .WithMany()
          .HasForeignKey(u =&gt; u.PosterId);
      }
  }
  public class PostCommentConfiguration : EntityTypeConfiguration&lt;PostComment&gt; {
      public PostCommentConfiguration() {
          // Comment has Response
          HasRequired(c =&gt; c.PostResponse)
          .WithMany(s =&gt; s.PostComments)
          .HasForeignKey(u =&gt; u.ResponseId);
      }
  }
  public class FlagCommentConfiguration : EntityTypeConfiguration&lt;FlagComment&gt; {
      public FlagCommentConfiguration() {
          // Comment has Response
          HasRequired(c =&gt; c.FlagResponse)
          .WithMany(s =&gt; s.FlagComments)
          .HasForeignKey(u =&gt; u.ResponseId);
      }
  }
  </code></pre>
  
  <p>I even tried adding a new ResponseId to the derived Comment classes just to see if I could budge this forward: </p>
  
  <pre><code>    [Required]
      public new int ResponseId { get; set; }
  </code></pre>
  
  <p>To no avail - I get the same error.  Why is this not working?</p>