title: Entity Framework v6, Correct way of deleting a record from table with multiple level relationships. i.e Parent - Child - SubChild
body: <p>I've a Table <code>SiteReport</code> which can have Many <code>Asset</code>, And each Asset can only have one <code>Certificate</code>. So its One-to-Many &amp; then One-to-One relationship. As shown below.</p>
  
  <p><a href="https://i.stack.imgur.com/t4yYl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t4yYl.jpg" alt="enter image description here"></a></p>
  
  <p>I'm trying to delete a SiteReport in the given method, So that all Assets under the Report and all associated Certificates will be deleted.</p>
  
  <pre><code>public ActionResult DeleteSiteReport(long siteReportId)
      {
          SiteReport report;
          List&lt;Asset&gt; reportAssets;
  
          using (var ctx = new ApplicationDbContext())
          {
              report = ctx.SiteReport.Include(i =&gt; i.Assets).SingleOrDefault(x =&gt; x.site_report_id == siteReportId);
              reportAssets = ctx.Asset.Include(i =&gt; i.Certificate).Where(x =&gt; x.site_report_id == siteReportId).ToList&lt;Asset&gt;();
  
              foreach (Asset asset in reportAssets)
              {
                  Certificate cert = ctx.Certificate.SingleOrDefault(x =&gt; x.report_asset_id == asset.report_asset_id);
                  ctx.Certificate.Remove(cert);
                  ctx.Asset.Remove(asset);
              }
  
              ctx.SiteReport.Remove(report);
  
              ctx.SaveChanges();
          }
  
          return RedirectToAction("ViewReports");
      }
  </code></pre>
  
  <p>Is this a correct/best way of doing it ? How to failproof it?</p>