public void Delete(string id) { Student student = _context.Students.Where(s => s.ID == id).Single(); var model = _context.Activities.Where(a => a.StudentID == id); foreach (Activity activity in model) { _context.Remove(activity); } _context.Students.Remove(student); _context.SaveChanges(); }
public void Delete(CourseStudent courseStudent) { string courseID = courseStudent.CourseID; string studentID = courseStudent.StudentID; List <Activity> activities = _context.Activities.Where(a => a.CourseID == courseID && a.StudentID == studentID).ToList(); foreach (Activity activity in activities) { _context.Activities.Remove(activity); } _context.Remove(courseStudent); _context.SaveChanges(); }