title: Remove cascade on delete from a single path
body: <p>Follwing my data models. I stripped all the unimportant annotations to keep it short and clean.</p>
  
  <pre><code>public class Bubble
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public ICollection&lt;Level&gt; Levels { get; set; }
  }
  
  public class Level
  {
      public int Id { get; set; }
      public int BubbleId { get; set; }
      [ForeignKey("ParentLevel")]
      public int? LevelId { get; set; }
  
      public string Name { get; set; }
  
      public Level ParentLevel { get; set; }
      public Bubble Bubble { get; set; }
  
      public ICollection&lt;Level&gt; Levels { get; set; }
      public ICollection&lt;Item&gt; Items { get; set; }
  }
  
  public class Item
  {
      public int Id { get; set; }
      public int LevelId { get; set; }
  
      public string Name { get; set; }
  
      public Level Level { get; set; }
  }
  </code></pre>
  
  <p>If i create it like that i will get the error: </p>
  
  <blockquote>
    <p>'Introducing FOREIGN KEY constraint 'FK_dbo.Item_dbo.Level_LevelId' on table 'Item' 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 or index. See previous errors.'</p>
  </blockquote>
  
  <p>If i add this code the database creation works:</p>
  
  <pre><code>modelBuilder.Entity&lt;Item&gt;()
      .HasRequired(i =&gt; i.Level)
      .WithMany(l =&gt; l.Items)
      .HasForeignKey(i =&gt; i.LevelId)
      .WillCascadeOnDelete(false);
  </code></pre>
  
  <p>But then i get this error when i delete a bubble:</p>
  
  <blockquote>
    <p>SqlException: The DELETE statement conflicted with the REFERENCE constraint "FK_dbo.Item_dbo.Level_LevelId". The conflict occurred in database "MvBubbles1", table "dbo.Item", column 'LevelId'.
    The statement has been terminated.</p>
  </blockquote>
  
  <p>So i belive the problem is that Level is self referencing. Because i have many one to many relationships and cascade on delete works everywhere except between Level and Item, the only difference is that the parent is not self referencing in the cases that work. I belive i just have to remove one cascade path but at the moment i can't figure out how to do this and where exactly the problem is without disabling cascade on delete out right but i don't want to disable it. </p>
  
  <p>Delete code:</p>
  
  <pre><code>db.Bubbles.Remove(bubble);
  db.SaveChanges();
  </code></pre>