Hi,
I have two Entities "Article" and "Picture", and there is a "Comment" Entity to hold the comments for any Article and Picture. (I know i can have two tables for comments, ArticleComment and PictureComment)
The Comment table structure is;
Id numeric(18,0) System.Long
CommentType byte CommentType (CommentType.Article, CommentType.Picture)
ItemId numeric(18,0) System.Long
Body nvarchar(max) string
If i had two tables for comments i mean ArticleComment and PictureComment, i just can did this
db.Article.Include("ArticleComment").FirstOrDefault(a=>a.id == articleId);
But if i just have one table for Comments i cant do this. Because i need to specify the CommentType.
I guess i could retrieve Comments for any Article or Picture entity like this ?
db.Article.Include("Comment").FirstOrDefault(a=>a.id == itemId && a.CommentType == CommentType.Article);
But there could be a problem while saving a comment because itemId can be the same on different CommentTypes (assume that Comment.ItemId is associated with Picture.Id and Article.Id in database so in EF Model)
Comment
Id CommentType ItemId Comment
--- ----------- ------ -------
1 1 5 Comment for 5th Picture
2 2 5 Comment for 5th Article
So is it possible to hold comments in one table for two different types of Entity by the help of Custom Enum CommentType