Saturday, November 5, 2011

a better posting on selecting from collections within collections by way of Lambdas!

I've tried to write a few quick blog postings on selecting from collections within collections by way of a Lambda and as I have done so I have made some mistakes as I myself am learning. In summary:

  1. I first wrote this which was pretty sound.
  2. .Any would not work with a comparison against a collection however so I wrote this which was flawed.
  3. I followed up with this correction, and in doing so I wondered what the appropriate use of .Select would be.
  4. It isn't too shabby for reaching two levels down a hierarchy. Behold:
    return new AdHocSpecification<Foo>(f => f.Bars.Select(br => br.Bazes).Where(bz => bz.Where(baz => baz.Qux == true).Count() > 0).Count() > 0);

No comments:

Post a Comment