Ok, I'm trying to get this working. This is my first time using LINQ. So far it's ok except a little snag that I've been trying to figure out.
Scenario: I have 2 generic lists I'm sending to a method. That method has this in it below to give me back a list of only those objects (union) where a certain ID is found in both. The lists could have different lengths and different order of IDs. The goal or what I want to do is get back from comparing those 2 lists, a list of objects where both have the same IDs. But furthermore when I find a matched object in both those lists (by id) don't give me back that object yet unless the call to OptionsMatch is also true (so that's why I have the &&).
The main problem I've had is that the lists can be totally different in length and have even differences in the list of IDs. But we know that all the lists we are passing to my method will have some commonality in terms of some of those objects will match by ID...no matter what lenth or order the 2 lists we are comparing are...we want the union of the lists back but only if also the call to OptionsMatch for that matched set of IDs match also.
Here's my LINQ statement (original)
List<SavedItemOption> finalItemOptions = savedItemOptions.Where(y => itemOptions.All(x => OptionsMatch(x,y) && (y.actID == x.Id))).ToList();
I've recently changed it to this:
List finalItemOptions = savedItemOptions.Where(y => (y.actID == x.Id) && itemOptions.All(x => OptionsMatch(x,y))).ToList();
but again, the problem is, LINQ is comparing the first Id in y with every other id in x. That's great. Take the first y.actID and look through all of x's x.ID. But then it stops. It doesn't then move to next savedItemOptions index and compare y.actID to all of x's x.IDs again.