我有三个模型:Document、Section和Paragraph。每一个看起来都是这样的。
// Document
public class Document
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Section> Sections { get; set; }
}
// Section
public class Section
{
public int Id { get; set; }
public int DocumentId { get; set; }
public virtual Document Document { get; set; }
public virtual ICollection<Paragraph> Paragraphs { get; set; }
}
// Paragraph
public class Paragraph
{
public int Id { get; set; }
public int SectionId { get; set; }
public virtual Section Section { get; set; }
}
实体会自动填充Section.Paragraphs其中的所有段落SectionId == Id。尽管对于Document.Sections. 而不是Document.Sections填充DocumentId == id,Document.Sections为空的所有部分。啊!