title: How to delete child entities before parent with Entity Framework CF?
body: <p>I am trying to use EF code-first to delete a db record (<code>deleteMe</code>) and it's children (<code>deleteMe.Prices</code>).</p>
  
  <pre><code>foreach (var deleteMe in deleteThese)
  { 
     // Delete validation
     if(CanDeleteItem(deleteMe.ItemId))
     {
        db.Entry(deleteMe).State = EntityState.Deleted;
  
        foreach (var item in deleteMe.Prices)
        {
           db.Entry(item).State = EntityState.Deleted; // cascade delete
        }
     }
  }
  db.SaveChanges();
  </code></pre>
  
  <p>However, Entity Framework seems to be unable to track the fact that the child records should be deleted before the parent. I get the error:</p>
  
  <blockquote>
    <p>The DELETE statement conflicted with the REFERENCE constraint "ItemPrice_Item".<br>
    The conflict occurred in database "DEVDB", table "dbo.ItemPrices", 
    column 'Item_ItemId'.<br>
    The statement has been terminated.</p>
  </blockquote>
  
  <p>How would I execute this delete in EF?</p>