Search code examples
c#linq

Linq Select Subset of master list


I have a master list of complex objects.

I have a list of int ids that I need to select the corresponding complex object out of the master list.

this doesn't work

MasterListofComplexObj.Where(u => MasterListofComplexObj.Select(i => i.Id).Contains(ChildListofIntIds));

any help would be appreciated.


Solution

  • This should work:

    var results = MasterListofComplexObj.Where(u => ChildListofIntIds.Contains(u.Id));