It should be the same. SelectMany boils down to

IEnumerable<TChild> SelectMany<TParent, TChild>(this IEnumerable<TParent>
parents, Func<TParent, IEnumerable<TChild>> selector)
{
  foreach(var parent in parents)
    foreach(var child in selector(parent))
      yield return child;
}

In the first case (below) the "selector" contains the where. In the second,
Where is applied after the child element is yielded. Either way nothing
happens until you actually iterate through the result anyway

Michael M. Minutillo
Indiscriminate Information Sponge
http://codermike.com


On Fri, Mar 2, 2012 at 1:20 PM, Greg Keogh <[email protected]> wrote:

> Ooops, my original code is correct, but I typed this in the post:****
>
> ** **
>
> ParentColl.SelectMany(p => p.ChildColl).Where(c => c.Type == "Foo");****
>
> ** **
>
> I meant:****
>
> ** **
>
> ParentColl.SelectMany(p => p.ChildColl.Where(c => c.Type == "Foo"));****
>
> ** **
>
> They produce the same result. The first would select all children before
> filtering. The second would filter then select. Whether there is any actual
> implementation difference I dunno, but I prefer the second.****
>
> ** **
>
> Greg****
>

Reply via email to