TPH pattern in ef core for a shared table between different entities

210 views Asked by At

i have a question. please suppose that we have different entities like category,blog,videos,... and each of them has own comments. how can i use one comment table for all of these entities just using one FK?is that TPH pattern?how can i implement it in codefirst approach? something like this Comments(CommentID, ..., PostID, VideoID) to Comments(CommentID). thanks in advance.

1

There are 1 answers

1
David Browne - Microsoft On

You can eliminate the FK from the comments table by using Many-to-Many relationships or separate linking entities for the relationships.