I had two List
of class myListClass
Where
public class myListclass
{
public Nullable<decimal> ClassId { get; set;}
public Nullable<decimal> SectionId { get; set; }
public Nullable<decimal> MediumId { get; set; }
public Nullable<decimal> StreamId { get; set; }
public Nullable<decimal> ShiftId { get; set; }
}
where list1 is
List<myListclass> liAll = new List<myListclass>();
and items in liAll
are
ClassId Section MediumId Stream Shift
73 220 207 145 128
73 221 207 145 128
73 222 207 145 128
74 220 207 145 128
74 221 207 145 128
75 220 207 145 128
75 221 207 145 128
76 220 207 145 128
76 221 207 145 128
77 220 207 145 128
77 221 207 145 128
78 220 207 145 128
And list2 is
List<myListclass> liJoin = new List<myListclass>();
Where item in liJoin
are
ClassId Section MediumId Stream Shift
73 220 207 145 128
73 221 207 145 128
Now I want to select only those items into a list which are in liAll
but not in liJoin
So wrote the following code:
List<myListclass> liFinal = new List<myListclass>();
liFinal = liAll.Where(w => !liJoin.Contains(w)).ToList();
but liFinal
not giving me accurate result it gives all items of liAll
So my questions are
- what's wrong with above code ?
Better way to do this
Updated code
liFinal = liAll.Where(w => !liJoin.Select(s => s.ClassId ).Contains(w.ClassId) &&
!liJoin.Select(s => s.MediumId ).Contains(w.MediumId) &&
!liJoin.Select(s => s.SectionId ).Contains(w.SectionId) &&
!liJoin.Select(s => s.ShiftId).Contains(w.ShiftId) &&
!liJoin.Select(s => s.StreamId).Contains(w.StreamId)).ToList();