how to loop and delete record from database in table EmployeeCourse table
this is my code
when itry to delete record from removedCourseIds collection it give me error
cannot convert from int to Models.employeecourse
- [HttpPost]
- ic ActionResult Edit(EditEmployeeVm model)
-
- {
- var existingCourseIds = db.EmployeeCourses.Where(g => g.EmployeeId == model.Id && g.CourseId!=null)
- .Select(f => f.CourseId.Value).ToList();
- var removedCourseIds = existingCourseIds.Except(model.CourseIds);
-
- foreach (var removedCourseId in removedCourseIds)
- {
- //here error show in variable removedCourseId and show red line under this variable in line of remove
- db.EmployeeCourses.Remove(removedCourseId);
- }
-
-
- db.SaveChanges();
-
-
- return View();
- }