Compare two object lists with LINQ on specific property
- by Niklas
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);