如何设计可以参考问题表或答案表的评论表?

发布于 2025-02-08 19:57:24 字数 980 浏览 4 评论 0原文

为了说明目的,让我们考虑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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪化雨蝶 2025-02-15 19:57:25

没有什么!将其留在ef上,它将管理这些关系。请注意,我可以说关系是一对多的答案问题有自己的注释钥匙,您必须使用两个键

nothing! leave it to EF, it will manage these relations. as a note, I can say the relations are one-to-many each Answer and Question has own Comment so if you want to put foreign keys you must use two keys for both of them

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文