c# - Linq - get objects with a list property that does not contain values in another list -


i feel complete idiot not being able work out myself.

i have list of "booking" objects called existingbookings. have observablecollection of "count" objects each of has "bookings" property list of "booking" objects.

using linq, how select count objects "bookings" property not contain of "booking" objects in existingbookings?

i.e.

list<booking> existingbookings = new list<booking>(); existingbookings.add(booking1); existingbookings.add(booking2);  count1 = new count(); count1.bookings.add(booking2); count1.bookings.add(booking3);  count2 = new count(); count1.bookings.add(booking3); count1.bookings.add(booking4);  list<count> counts = new list<count>(); counts.add(count1); counts.add(count2); 

i expecting output list of count objects containing count2, since neither of booking objects exist in existingbookings.

please put me out of misery :(

assuming booking class implements equality , hash codes correctly can use:

var result = counts.where(c => !c.bookings.intersect(existingbookings).any()); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -