C
C#3y ago
Ice_

❔ Entity Framework - paired tables. Can add but not remove from paired table?

I've setup a Student class and a Course class. I've added the properties and also added necessary dbset in the dbcontext class. I've added two students manually, one with id 1 and another with id 2 of course. Same goes with courses. (dbc = dbcontext) I then add a course to student 2 with: Student student = dbC.Students.First(s => s.StudentID == 2); Course course = dbC.Courses.First(s => s.CourseId == 2); student.Course.Add(course); This will add to the the CourseStudent table: CorseId: 2 | StudentStudentID: 2 (note: Why does it name the column to StudentStudentID and not the same with CorseId?) If I repeat the code above but change from Add to Remove, it does not remove it. I've added a breakpoint and if I hove above course variable it will say that "Students" is null. Where did things go wrong? 😅
3 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Ice_
Ice_OP3y ago
Thanks Divi! You are right, the include part was the missing piece!
Accord
Accord3y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server