我在我的項目中有以下情況,我開始有幾個關於它的問題。兩個具有常見一對多關係的實體
在User
類,查詢QuestionFollows
直接會更好(在性能方面)不是查詢Questions
然後QuestionFollows
?
另一個問題...... User
和QuestionFollow
必要/ redudant之間的關係?你正在做
域
public class User
{
public long UserID { get; set; }
public string Name { get; set; }
public virtual ICollection<Question> Questions { get; set; }
public virtual ICollection<QuestionFollow> QuestionFollows { get; set; }
}
public class Question
{
public long QuestionID { get; set; }
public long UserID { get; set; }
public string Description { get; set; }
public User User { get; set; }
public virtual ICollection<QuestionFollow> QuestionFollows { get; set; }
}
public class QuestionFollow
{
public long QuestionFollowID { get; set; }
public long QuestionID { get; set; }
public long UserID { get; set; }
public DateTime Date { get; set; }
public Question Question { get; set; }
public User User { get; set; }
}
查詢QuestionFollows在用戶不會給你相同的行查詢問題然後QuestionFollows。 QuestionFollows on User就像'User.Questions.SelectMany(x => x.QuestionFollows)'。在這種情況下,直接在User上的QuestionFollow比Select many選項具有更好的性能 –