title: MVC .Net Cascade Deleting when using EF Code First Approach
body: <p>I'm pretty new to MVC and i'm having troubles with cascade deleting. For my model I the following 2 classes:</p>
  
  <pre><code>    public class Blog
      {
          [Key]
          public int Id { get; set; }
          [Required]
          public string Name { get; set; }
          [DisplayFormat()]
          public virtual ICollection&lt;BlogEntry&gt; BlogEntries { get; set; }
          public DateTime CreationDateTime { get; set; }
          public string UserName { get; set; }
      }
  
      public class BlogEntry
      {
          [Key]
          public int Id { get; set; }
          [Required]
          public string Title { get; set; }
          [Required]
          public string Summary { get; set; }
          [Required]
          public string Body { get; set; }
          public List&lt;Comment&gt; Comments { get; set; }
          public List&lt;Tag&gt; Tags { get; set; }
          public DateTime CreationDateTime { get; set; }
          public DateTime UpdateDateTime { get; set; }
          public virtual Blog ParentBlog { get; set; }
  
      }
  </code></pre>
  
  <p>And for my controller I set he following on delete post back:</p>
  
  <pre><code>[HttpPost, ActionName("Delete")]
  public ActionResult DeleteConfirmed(int id)
  {
      Blag blog = db.Blogs.Find(id);
  
      foreach (var blogentry in blog.BlogEntries)
      {
          //blogentry = db.BlogEntries.Find(id);
          db.BlogEntries.Remove(blogentry);
      }
      db.Blogs.Remove(blog);
      db.SaveChanges();
      return RedirectToAction("Index");
  }
  </code></pre>
  
  <p>Problem is it wont work no matter what; <a href="https://stackoverflow.com/questions/5825799/cascade-delete-rule-in-ef-4-1-code-first-when-using-shared-primary-key-associati">I read this post</a> but i seem to only work for models where the relation is one to one, so i'm lost here, i have search everywhere, and can't find the solution for this problem, if some could point out what i'm missing it would be really nice :), thanks in advance, and again, pardon my nooobness i'm just getting started, but wanted to tackle a big project to be able to learn a lot.</p>