title: Entity Framework delete child object
body: <p>I have two tables without any cascade deleting. I want to delete parent object with all child objects. I do it this way</p>
  
  <pre><code>//get parent object
  return _dataContext.Menu.Include("ChildMenu").Include("ParentMenu").Include("Pictures").FirstOrDefault(m =&gt; m.MenuId == id);
  //then i loop all child objects
  var picList = (List&lt;Picture&gt;)menu.Pictures.ToList();
  
  for (int i = 0; i &lt; picList.Count; i++)
   {
    if (File.Exists(HttpContext.Current.Server.MapPath(picList[i].ImgPath)))
    {
       File.Delete(HttpContext.Current.Server.MapPath(picList[i].ImgPath));
    }
    if (File.Exists(HttpContext.Current.Server.MapPath(picList[i].ThumbPath)))
    {
       File.Delete(HttpContext.Current.Server.MapPath(picList[i].ThumbPath));
    }
  
    //**what must i do here?**
    //menu.Pictures.Remove(picList[i]);
    //                DataManager dm = new DataManager();
    //                dm.Picture.Delete(picList[i].Id);
  
    //menu.Pictures.de
    //_dataContext.SaveChanges();
    //picList[i] = null;
  
  }
  
  //delete parent object
  _dataContext.DeleteObject(_dataContext.Menu.Include("ChildMenu").Include("ParentMenu")
      .Include("Pictures").FirstOrDefault(m =&gt; m.MenuId == id););
  _dataContext.SaveChanges();
  </code></pre>