私には、Document
,Section
、およびParagraph
という3つのモデルがあります。それぞれはこのように見えます。なぜEntityは自動的に関係を完了しませんか?
// 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; }
}
エンティティは自動的にすべての段落SectionId == Id
とSection.Paragraphs
に移入されます。しかし、これは起こっていません。Document.Sections
です。 Document.Sections
の代わりにDocumentId == id
、Document.Sections
のすべてのセクションが入力されます。アー!
これらの関係はデータベースに定義されていますか? – MrFox
エンティティによって自動的に定義される必要があります。 –
@dunsmoreb最初にdbを使用していて、データベースに外部キーとして定義されていない場合EFはそれらをほとんど定義しません –