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);
- //Now loop through these and delete it from db
- 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();
- }
Manas MohapatraRank #182 · 13.2K reputationPosted Sep 7, 2016, 1:03 AM EDT
ahmed salahRank #2,612 · 534 reputationPosted Sep 7, 2016, 4:01 AM EDT
Manas MohapatraRank #182 · 13.2K reputationPosted Sep 7, 2016, 5:06 AM EDT
ahmed salahRank #2,612 · 534 reputationPosted Sep 7, 2016, 3:38 PM EDT
ahmed salahRank #2,612 · 534 reputationPosted Sep 7, 2016, 3:40 PM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts