I have two entities, Student and Course. Given a student ID and course ID, I need to remove their relationship (meaning that a student won’t take that course anymore) (please note I don’t need to remove the student and course themselves, just their relationship).
I tried with Students.Courses.Clear(), but it clears every single course and not a specific one. Thank you.
EDIT:
In the database, Student and Course are related through a StudentCourse table with 2 columns: StudentID and CourseID.
I would normally delete the row to remove the relationship, but when the model was generated from the database, it didn’t create an entity for this table. Instead, Student and Course are navigation properties of each other and their Association is set to the StudentCourse table. Thank you.
You will have a student, course and something like enrolled course which holds the id of the course and the student. Just delete that record when they drop out or create one when a student enrolls.
In EF probably something like this:
then submit your changes.