I've followed the docs for setting up my many-to-many relationship, using a join table that is exposed as an entity.
But the docs don't mention what I should do about deletion.
So for example, a Student
has many teachers, and a Teacher
has many students. The join entity/table is StudentTeacher
.
The join table/entity:
public class StudentTeacher {
public int StudentId { get; set; }
public Student Student { get; set; }
public int TeacherId { get; set; }
public Teacher Teacher { get; set; }
}
The config for the join table/entity:
modelBuilder.Entity<StudentTeacher>()
.HasOne(b => b.Teacher)
.WithMany(b => b.StudentTeachers)
.HasForeignKey(b => b.TeacherId)
.IsRequired()
.OnDelete(/* ... what goes here? ...*/);
modelBuilder.Entity<StudentTeacher>()
.HasOne(b => b.Student)
.WithMany(b => b.StudentTeachers)
.HasForeignKey(b => b.StudentId)
.IsRequired()
.OnDelete(/* ... what goes here? ...*/);
What do I use in OnDelete()
? And why?