ahmed salah

ahmed salah

  • NA
  • 530
  • 147.9k

cannot convert from int to Models.employeecourse error

Sep 6 2016 5:31 PM
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)