Saturday, November 5, 2011

another way to loop through collections within a collection in a Lambda

Here I suggest a way to loop through a collection within a collection like so:

var foo = bars.Where(b => b.bazes.Any(bz => quxIds.Contains(bz.Id)));

 
 

I offer another way today:

return new AdHocSpecification<Program>(p => p.ProgramPlans.Select(pp => Ids.Contains(pp.Id)).Count() > 0);

 
 

Don't forget to add the using System.Linq; using statement. Duh. (.Select will not work with LinqSpecs alone.)

No comments:

Post a Comment