出于說明目的,讓我們考慮 3 個表:Question和Answer以下CommentORM 模型(在 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;}
}
問題
我不知道如何構建Comment屬性For可以是Questionor的表Answer。什么是For財產型別?
uj5u.com熱心網友回復:
沒有什么!留給它EF,它會管理這些關系。作為一個注釋,我可以說關系是一對多的Answer并且Question有自己的Comment,所以如果你想放置外鍵,你必須為它們使用兩個鍵
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/494604.html
