title: Entity Framework Core cascade delete one to many relationship
body: <pre><code>public class Station : IEntitie
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }
  
      public virtual ICollection&lt;RegulatorySchedule&gt; RegulatoryScheduleDispatchStations { get; set; }    
  
      public virtual ICollection&lt;RegulatorySchedule&gt; RegulatoryScheduleDestinationStations { get; set; }   
  }
  
  public class RegulatorySchedule : IEntitie
  {
      [Key]
      public int Id { get; set; }
  
      public virtual Station DispatchStation { get; set; }      
  
      public virtual Station DestinationStation { get; set; }     
  }
  
  
  protected override void OnModelCreating(ModelBuilder modelBuilder)
  {
          modelBuilder.Entity&lt;RegulatorySchedule&gt;()
              .HasOne(s =&gt; s.DestinationStation)
              .WithMany(s =&gt; s.RegulatoryScheduleDestinationStations)
              .OnDelete(Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior.Restrict);
  
          modelBuilder.Entity&lt;RegulatorySchedule&gt;()
              .HasOne(s =&gt; s.DispatchStation)
              .WithMany(s =&gt; s.RegulatoryScheduleDispatchStations)
              .OnDelete(Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior.Restrict);
  }
  </code></pre>
  
  <p>The database is created during migration only when I clearly expose the behavior when deleting <code>Restrict
  OnDelete (Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior.Restrict)</code>.
  Otherwise, it throws an exception:</p>
  
  <blockquote>
    <p>"Introducing FOREIGN KEY constraint
    'FK_RegulatorySchedules_Stations_DispatchStationId' on table
    'RegulatorySchedules' 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 need the removal of the Station Stations of the table and the table-related properties RegulatorySchedules DispatchStation and DestinationStation exposed to NULL.
  But Restrict option there is an exception when you delete a SetNull I can not put.
  Tell me how to be?</p>