I'm going for TPH inheritance here - one Comments table with a discriminator.
I keep getting the error:
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.
Whenever I try to perform a fresh migration.
Models:
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; }
}
Mappings:
public class CommentConfiguration : EntityTypeConfiguration<Comment> {
public CommentConfiguration() {
// Comment has Poster (From Message base class)
HasRequired(c => c.Poster)
.WithMany()
.HasForeignKey(u => u.PosterId);
}
}
public class PostCommentConfiguration : EntityTypeConfiguration<PostComment> {
public PostCommentConfiguration() {
// Comment has Response
HasRequired(c => c.PostResponse)
.WithMany(s => s.PostComments)
.HasForeignKey(u => u.ResponseId);
}
}
public class FlagCommentConfiguration : EntityTypeConfiguration<FlagComment> {
public FlagCommentConfiguration() {
// Comment has Response
HasRequired(c => c.FlagResponse)
.WithMany(s => s.FlagComments)
.HasForeignKey(u => u.ResponseId);
}
}
I even tried adding a new ResponseId to the derived Comment classes just to see if I could budge this forward:
[Required]
public new int ResponseId { get; set; }
To no avail - I get the same error. Why is this not working?