I am trying to implement a model in EF6 using inheritance
I have a the following classes:
Base
Comments
Page : Base
BlogPost : Base
Where both Page and BlogPost use comments in the same manner. So I define Base as
public class Base
{
public int ID { get; set; }
// ...
public ICollection<Comment> Comments { get; set; }
}
And the comments class defined like so:
public class Comment
{
public int ID { get; set; }
public int RelatedItemID { get; set; } // points to Base::ID
public string Text { get; set; }
}
Suppose I want to set up the database as "Table per Type", so there are individual tables for Page and BlogPost each with auto-increment int PK.
Now the EF know which table Comment.RelatedItemID points to? i.e. Page or BlogPost
What is the best way to implements this without having to resort to "Table Per Hierarchy"?