title: Entity Framework (Core) - cascading delete
body: <p>I’m using EF Core 3.1.1, but I believe this question applies to all versions of EF.</p>
  
  <p>It seems the EF has the ability to cascade delete - if it is enabled, and if the dependent objects are loaded in the context.</p>
  
  <pre><code>var blog = context.blogs.Include(x =&gt; x.Posts).First(x =&gt; x.BlogId == id);
  context.blogs.Remove(blog);
  </code></pre>
  
  <p>The above statement deletes all the blog’s posts, and then the blog - each with a different sql statement.</p>
  
  <p>This is what I want, however when using code-first, it also creates the tables with cascading delete enabled in the database. (<code>ON DELETE CASCADE</code>)</p>
  
  <p>Can you enable cascade delete in EF, and rely of EF deleting dependent objects, without also enabling database level cascade delete? (Or am I understanding this incorrectly?)</p>
  
  <p>The reason is migrations fail because SQL won’t enable cascade delete in the database because it detects multiple cascade paths (even though multiple wouldn’t occur naturally in the schema)</p>
  
  <p>Thanks!</p>