title: How to solve multiple cascade paths with entity code first
body: <p>A <code>Template</code> can have zero or many <code>Document</code> and zero or many <code>MetaIndex</code>. A <code>Document</code> can have zero or more <code>Index</code>, and a <code>MetaIndex</code> can also have zero or more <code>Index</code>:</p>
  
  <p><img src="https://i.stack.imgur.com/fOxIm.png" alt="enter image description here"></p>
  
  <p>This represent a potential cascade problem because deleting a <code>Template</code> will delete its <code>Document</code> (which is OK); deleting a <code>Document</code> will delete its <code>Index</code>, which is also OK. But when deleting a <code>Template</code> try to delete the <code>MetaIndex</code> (which will also delete <code>Index</code>) a problem will appear (a cycle). </p>
  
  <p>I understand the problem. I think a way to solve it is specifying that when I delete a template it's documents and its document's indices get deleted, and also the meta-indices associated with the template. But that the metaindices do not cascade delete it's associated indices, so no cycles appear. </p>
  
  <p>Searching here for a <a href="https://stackoverflow.com/questions/14489676/entity-framework-how-to-solve-foreign-key-constraint-may-cause-cycles-or-multi">potential solution</a>, I've tried this:</p>
  
  <pre><code>protected override void OnModelCreating(DbModelBuilder modelBuilder)
  {
      modelBuilder.Entity&lt;MetaIndex&gt;().HasMany&lt;Index&gt;(m =&gt; m.IndicesEnteros).WithRequired().WillCascadeOnDelete(false);
  }
  </code></pre>
  
  <p>But it's not working: </p>
  
  <blockquote>
    <p>Introducing FOREIGN KEY constraint on table may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint. See previous errors.</p>
  </blockquote>