title: Loading all the children entities with entity framework
body: <p>I have a data model like this</p>
  
  <p><img src="https://i.stack.imgur.com/KodFQ.png" alt="Data Model"></p>
  
  <p>I would like to load all the related entities from a Reconciliation into a Reconciliation object. </p>
  
  <p>For now the only way I could find to load all the related entites to a single Recon is in multiple Lists. <strong>But I want to load every related entities in a <code>Reconciliation</code> object.</strong> If possible in an elegant way.</p>
  
  <pre><code>Reconciliation recon = db.Reconciliations
    .Where(r =&gt; r.ReconNum == 382485).First();
  
  List&lt;ReconciliationDetail&gt; reconDetails = recon.ReconciliationDetails.ToList();
  List&lt;JrnlEntryDetail&gt; jrnlDetails = reconDetails.Select(r =&gt; r.JrnlEntryDetail).ToList();
  List&lt;JrnlEntry&gt; jrnl = jrnlDetails.Select(j =&gt; j.JrnlEntry).ToList();
  
  List&lt;ARInvoice&gt; invoices = jrnl.SelectMany(j =&gt; j.ARInvoices).ToList();
  List&lt;ARInvoiceDetail&gt; invoicesDetail = invoices
    .SelectMany(i =&gt; i.ARInvoiceDetails).ToList();
  
  List&lt;ARCredMemo&gt; credmemos = jrnl.SelectMany(j =&gt; j.ARCredMemoes).ToList();
  List&lt;ARCredMemoDetail&gt; credmemosDetail = credmemos
    .SelectMany(c =&gt; c.ARCredMemoDetails).ToList();
  
  List&lt;IncomingPay&gt; incomingPays = jrnl.SelectMany(j =&gt; j.IncomingPays).ToList();
  List&lt;IncomingPayDetail&gt; incomingPaysDetail = incomingPays
    .SelectMany(i =&gt; i.IncomingPayDetails).ToList();
  
  // ... and so on for outgoing pays, AP Invoices AP Cred Memo ...etc
  </code></pre>
  
  <p>I have also tried to load it with <code>Include</code> and <code>Select</code> but I get this exception : </p>
  
  <p><em>The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.</em> </p>
  
  <p>And I don't get how I could load every childs of JrnlEntry using <code>Include</code> and <code>Select</code></p>
  
  <pre><code>Reconciliation recon = db.Reconciliations
    .Where(r =&gt; r.ReconNum == 382485)
    .Include(r =&gt; r.ReconciliationDetails
      .Select(d =&gt; d.JrnlEntryDetail)
      .Select(jd =&gt; jd.JrnlEntry)
      .SelectMany(j =&gt; j.ARInvoices).SelectMany(i =&gt; i.ARInvoiceDetails))
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>Managed to do it this way too but it's not very beautiful : </p>
  
  <pre><code>Reconciliation recon = db.Reconciliations
  .Where(r =&gt; r.ReconNum == 382485)
    .Include(r =&gt; r.ReconciliationDetails.Select(rd =&gt; rd.JrnlEntryDetail)
      .Select(jd =&gt; jd.JrnlEntry).Select(j =&gt; j.ARInvoices.Select(i =&gt; i.ARInvoiceDetails)))
    .Include(r =&gt; r.ReconciliationDetails.Select(rd =&gt; rd.JrnlEntryDetail)
      .Select(jd =&gt; jd.JrnlEntry).Select(j =&gt; j.ARCredMemoes.Select(c =&gt; c.ARCredMemoDetails)))
    .Include(r =&gt; r.ReconciliationDetails.Select(rd =&gt; rd.JrnlEntryDetail)
      .Select(jd =&gt; jd.JrnlEntry).Select(j =&gt; j.IncomingPays.Select(i =&gt; i.IncomingPayDetails)))
    .Include(r =&gt; r.ReconciliationDetails.Select(rd =&gt; rd.JrnlEntryDetail)
      .Select(jd =&gt; jd.JrnlEntry).Select(j =&gt; j.OutgoingPays.Select(o =&gt; o.OutgoingPayDetails)))
    .Include(r =&gt; r.ReconciliationDetails.Select(rd =&gt; rd.JrnlEntryDetail)
      .Select(jd =&gt; jd.JrnlEntry).Select(j =&gt; j.APInvoices.Select(o =&gt; o.APInvoiceDetails)))
    .Include(r =&gt; r.ReconciliationDetails.Select(rd =&gt; rd.JrnlEntryDetail)
      .Select(jd =&gt; jd.JrnlEntry).Select(j =&gt; j.APCredMemoes.Select(o =&gt; o.APCredMemoDetails)))
    .Include(r =&gt; r.ReconciliationDetails.Select(rd =&gt; rd.JrnlEntryDetail)
      .Select(jd =&gt; jd.JrnlEntry).Select(j =&gt; j.JrnlEntryDetails))
  </code></pre>