如何设计可以参考问题表或答案表的评论表?
为了说明目的,让我们考虑3个表:问题
,答案
和用以下ORM模型(在C#中)进行注释
。
- 一个问题可以具有零或更多答案和/或评论。
- 答案属于问题,并且可以具有零或更多评论。
- 评论属于问题或答案。
规则模仿SO/SE机制。
class Question
{
public int Id {get; set;}
public string Content {get; set;}
public IEnumerable<Answer> Answers {get; set;}
public IEnumerable<Comment> Comments {get; set;}
}
class Answer
{
public int Id {get; set;}
public string Content {get; set;}
public Question Question {get; set;}
public IEnumerable<Comment> Comments {get; set;}
}
class Comment
{
public int Id {get; set;}
public string Content {get; set;}
public ?????? For {get; set;}
}
问题
我不知道如何构造注释
表,其中属性可以是问题
或答案
。 属性的类型是什么?
For illustration purposes, let's consider 3 tables: Question
, Answer
and Comment
with the following ORM models (in C#).
- A question can have zero or more answers and/or comments.
- An answer belongs to a question and can have zero or more comments.
- A comment belongs to either a question or an answer.
The rules mimic SO/SE mechanism.
class Question
{
public int Id {get; set;}
public string Content {get; set;}
public IEnumerable<Answer> Answers {get; set;}
public IEnumerable<Comment> Comments {get; set;}
}
class Answer
{
public int Id {get; set;}
public string Content {get; set;}
public Question Question {get; set;}
public IEnumerable<Comment> Comments {get; set;}
}
class Comment
{
public int Id {get; set;}
public string Content {get; set;}
public ?????? For {get; set;}
}
Question
I have no idea how to construct the Comment
table in which the property For
can be either Question
or Answer
. What is the type of For
property?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有什么!将其留在
ef
上,它将管理这些关系。请注意,我可以说关系是一对多的答案
和问题
有自己的注释
钥匙,您必须使用两个键nothing! leave it to
EF
, it will manage these relations. as a note, I can say the relations are one-to-many eachAnswer
andQuestion
has ownComment
so if you want to put foreign keys you must use two keys for both of them