title: Delete cascade using intermediate table
body: <p>I have these entities <code>Course</code> and <code>Student</code> and an intermediate table <code>CourseStudent</code>.</p>
  <pre><code>public class Course
  {
      public decimal Id { get; set; }
      public decimal IdState { get; set; }
      public decimal IdCity { get; set; }
      public string Name { get; set; }
      public List&lt;CourseStudent&gt; CourseStudents { get; set; } = new List&lt;CourseStudent&gt;();
  }   
  public class Student
  {
      public decimal Id { get; set; }
      public decimal IdState { get; set; }
      public decimal IdCity { get; set; }
      public string Name { get; set; }
      public List&lt;CourseStudent&gt; CourseStudents { get; set; } = new List&lt;CourseStudent&gt;();
  }
  
  public class CourseStudent
  {
      public decimal Id { get; set; }
      public decimal IdState { get; set; }
      public decimal IdCity { get; set; }
      public decimal IdCourse { get; set; }
      public decimal IdStudent { get; set; }
      public Course Course { get; set; }
      public Student Student { get; set; }
  }
  </code></pre>
  <p>My Configuration files:</p>
  <pre><code>public class CourseStudentConfiguration : IEntityTypeConfiguration&lt;CourseStudent&gt;
  {
      public void Configure(EntityTypeBuilder&lt;CourseStudent&gt; builder)
      {
          builder.ToTable(&quot;Courses_Students&quot;);
          builder.Property(x =&gt; x.IdState).HasColumnType(&quot;numeric(18,0)&quot;).IsRequired();
          builder.Property(x =&gt; x.IdCity).HasColumnType(&quot;numeric(18,0)&quot;).IsRequired();
          builder.Property(x =&gt; x.IdCourse).HasColumnType(&quot;numeric(18,0)&quot;).IsRequired();
          builder.Property(x =&gt; x.IdStudent).HasColumnType(&quot;numeric(18,0)&quot;).IsRequired();
  
          builder
              .HasOne(x =&gt; x.Course)
              .WithMany(x =&gt; x.CourseStudents)
              .HasForeignKey(x =&gt; x.IdCourse)
              .OnDelete(DeleteBehavior.Cascade);
  
          builder
              .HasOne(x =&gt; x.Student)
              .WithMany(x =&gt; x.CourseStudents)
              .HasForeignKey(x =&gt; x.IdStudent)
              .OnDelete(DeleteBehavior.Cascade);
      }
  }
  </code></pre>
  <p>As you can see, my relations are only in my intermediate table.</p>
  <pre><code>public class CourseConfiguration : IEntityTypeConfiguration&lt;Course&gt;
  {
      public void Configure(EntityTypeBuilder&lt;Course&gt; builder)
      {
          builder.ToTable(&quot;Courses&quot;);
          builder.Property(x =&gt; x.IdState).HasColumnType(&quot;numeric(18,0)&quot;).IsRequired();
          builder.Property(x =&gt; x.IdCity).HasColumnType(&quot;numeric(18,0)&quot;).IsRequired();
          builder.Property(x =&gt; x.Name).HasColumnType(&quot;varchar(64)&quot;).IsRequired();
      }
  }
  
  public class StudentConfiguration : IEntityTypeConfiguration&lt;Student&gt;
  {
      public void Configure(EntityTypeBuilder&lt;Student&gt; builder)
      {
          builder.ToTable(&quot;Students&quot;);
          builder.Property(x =&gt; x.IdState).HasColumnType(&quot;numeric(18,0)&quot;).IsRequired();
          builder.Property(x =&gt; x.IdCity).HasColumnType(&quot;numeric(18,0)&quot;).IsRequired();
          builder.Property(x =&gt; x.Name).HasColumnType(&quot;varchar(64)&quot;).IsRequired();
      }
  }
  </code></pre>
  <p><em>When I was deleting some <code>Course</code> the <code>CourseStudent</code> was deleted as was expected, but the <code>Student</code> was not deleted and I need the <code>Student</code> to be deleted too.</em></p>
  <p><strong>What changes do I need to do on <code>CourseStudentConfiguration</code> (or <code>StudentConfiguration</code>) in order to be deleted <code>Student</code> too when the <code>Course</code> is deleted.</strong></p>