Compare two object lists with LINQ on specific property

Posted by Niklas on Stack Overflow See other posts from Stack Overflow or by Niklas
Published on 2014-06-04T09:14:19Z Indexed on 2014/06/04 9:24 UTC
Read the original article Hit count: 170

Filed under:
|
|

I have these two lists (where the Value in a SelectListItem is a bookingid):

List<SelectListItem> selectedbookings;
List<Booking> availableBookings;

I need to find the ids from selectedBookings that are not in availableBookings. The LINQ join below will only get me the bookingids that are in availableBookings, and I'm not sure how to do it the other way around.

!= won't work since I'm comparing strings.

results = (
  from s in selectedbookings
  join a in availableBookings on s.bookingID.ToString() equals a.Value
  select s);

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ