我有3种型号:
Article
Course
Episode
他们所有人都有很多评论。
如何在这些模型与Comment
模型之间建立联系?
答案 0 :(得分:3)
假设您的文章,课程和情节中的ID为long
,在Comment模型中,您可以拥有类似的内容
public class Comment
{
public long CommentId { get; set; }
public string Message { get; set; }
public DateTime EntryDate { get; set; }
//Type to store Article, Course or Episode
public string Type { get; set; }
//TypeId to store the Id of the Article, Course or Episode
public long TypeId { get; set; }
}
您也可以将public string Type { get; set; }
更改为枚举,以使其更清晰易懂。