5
Answers

cannot convert from int to Models.employeecourse error

ahmed salah

ahmed salah

8y
318
1
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
  1. [HttpPost]  
  2. ic ActionResult Edit(EditEmployeeVm model)  
  3.      
  4.     {  
  5.         var existingCourseIds = db.EmployeeCourses.Where(g => g.EmployeeId == model.Id && g.CourseId!=null)  
  6.                          .Select(f => f.CourseId.Value).ToList();  
  7.         var removedCourseIds = existingCourseIds.Except(model.CourseIds);  
  8.         //Now loop through these and delete it from db  
  9.         foreach (var removedCourseId in removedCourseIds)  
  10.         {  
  11. //here error show in variable removedCourseId and show red line under this variable in line of remove
  12.             db.EmployeeCourses.Remove(removedCourseId);  
  13.         }  
  14.   
  15.   
  16.         db.SaveChanges();  
  17.   
  18.   
  19.         return View();  
  20.     }  
 
Answers (5)