views:

8

answers:

0

enter code hereHi , I have two list one the original data and the second is the list that is edited. Is it possible to get the inserted,deleted and updated object in the list by comparing ? I tried the below and its not working as expected.

   List<StudentList> originalStudentList = GetStudentsList();
   List<StudentList> EditedStudentList = GetEditedStudentsList();
   List<StudentList> insertedStudentList = null;
   List<StudentList> deletedStudentList = null;
   List<StudentList> updatedStudentList = null;



 insertedStudentList = originalStudentsList.Where(originalStudentList => EditedStudentsList.Where(StudentList => StudentList.ID != originalStudentList.ID && StudentList.IsGroup == originalStudentList.IsGroup).FirstOrDefault() == null).ToList(); 
deletedStudentList  = originalStudentsList.Where(originalStudentList => EditedStudentsList.Where(StudentList => StudentList.ID != originalStudentList.ID && StudentList.IsGroup == originalStudentList.IsGroup).FirstOrDefault() == null).ToList(); 
updatedStudentList = originalStudentsList.Where(originalStudentList => EditedStudentsList.Where(StudentList => (StudentList.ID == originalStudentList.ID && StudentList.IsGroup == originalStudentList.IsGroup) && (StudentList.Name != originalStudentList.Name || StudentList.HasPaidFee != originalStudentList.HasPaidFee || StudentList.HasPassed != originalStudentList.HasPassed)).FirstOrDefault() == null).ToList();