title: How to turn off cascade delete in Entity Framework Core 1.0 RTM
body: <p>Hi I have MVC 6 application with Entity Framework Core 1.0 RTM and SQL server, when I try to generate database tables, I got "Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths" error.</p>
  
  <p>My model classes are as below:</p>
  
  <p>Category Model:</p>
  
  <pre><code> public class Category
  {
      public Category()
      {
          this.VariableSettings = new List&lt;VariableSetting&gt;();
      }
      public int CategoryId { get; set; }
  
      public string CategoryName { get; set; }
  
      public List&lt;VariableSetting&gt; VariableSettings { get; set; }
  
      public List&lt;Station&gt; Stations { get; set; }
  }
  </code></pre>
  
  <p>Station Model:</p>
  
  <pre><code> public class Station
  {
      public int StationId { get; set; }
      public string StationName { get; set; }
  
      public double? Longitude { get; set; }
      public double? Latitude { get; set; }
  
      public List&lt;VariableRecord&gt; VariableRecords { get; set; }
  
      public int CategoryID { get; set; }
      public Category Category { get; set; }
  }
  </code></pre>
  
  <p>VariableRecord Model:</p>
  
  <pre><code> public class VariableRecord
  {
      [Key]
      public int VariableRecordId { get; set; }
      public double Value { get; set; }
      public DateTime RecordDate { get; set; }
  
      public int StationId { get; set; }
      public Station Station { get; set; }
  
      public int VarSettingId{ get; set; }
      public virtual VariableSetting VariableSetting { get; set; }
  }
  </code></pre>
  
  <p>VariableSetting Model:</p>
  
  <pre><code>public class VariableSetting
  {
      [Key]
      public int VarSettingId { get; set; }
      public int Sequence { get; set; }
      public double? MinimumValue { get; set; }
      public double? MaximumValue { get; set; }
  
      public int CategoryId { get; set; }
      public virtual Category Category { get; set; }
  
      public int VariableId { get; set; }
      public Variable Variable { get; set; }
  
      public List&lt;VariableRecord&gt; VariableRecords { get; set; }
  }
  </code></pre>
  
  <p>Variable Model:</p>
  
  <pre><code> public class Variable
  {
      public int VariableId { get; set; }
  
      public string VariableName { get; set; }
  
      public string Description { get; set; }
  
      public string Unit { get; set; }
  
      public List&lt;VariableSetting&gt; VariableSettings { get; set; }
  }
  </code></pre>
  
  <p>So, there are too Cascade delete routes in my codes Category->Station->VariableRecord and Category->VariableSetting->VariableRecord, so I am trying to diable the route Category->VariableSetting->VariableRecord in the context class with Fluent API as below:</p>
  
  <pre><code>builder.Entity&lt;VariableRecord&gt;()
          .HasOne(pt =&gt; pt.VariableSetting)
          .WithMany(p =&gt; p.VariableRecords)
          .HasForeignKey(pt =&gt; pt.VarSettingId)
          .OnDelete(DeleteBehavior.Cascade);
  </code></pre>
  
  <p>However I still got same as below:</p>
  
  <blockquote>
    <p>System.Data.SqlClient.SqlException (0x80131904): Introducing FOREIGN
    KEY constraint 'FK_VariableSetting_Category_CategoryId' on table
    'VariableSetting' may cause cycles or multiple cascade paths.Specify
    ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN
    KEY constraints.</p>
  </blockquote>
  
  <p>I have been stuck on these codes for couple of days but still went nowhere, please help!</p>