tags:

views:

128

answers:

1

Thanks to the help with this.

Tried this, without luck..

I know

from f in list 
where f.bar == someVar
select f

can be written as

list.Where( f => f.bar == someVar );

Can a similar expression be created from

from f in foo
from b in f.bar
where b.something == someVar
select f;

?

Edit: Sorry, I forgot f.bar in the second example is a list of objects.

+4  A: 

Definitely. Query syntax is just a syntactic sugar. It'll be translated to underlying lambda syntax by the compiler, so every query expression has an equivalent lambda based representation.

This is probably what you need (this is not strictly equivalent to that but works when you just have one bar matching the query in each foo):

var result = foo.Where(f => f.bar.Any(b => b.something == someVar));

The strictly equivalent version is:

var result = foo.SelectMany(f => f.bar, (f, b) => new { F = f, B = b })
                .Where(x => x.b.something == someVar)
                .Select(x => x.f);
Mehrdad Afshari