Consider the following function:
IQueryable<Bar> foo(IEnumerable<IQueryable<Bar>> sources)
{
return
from source in sources.AsQueryable()
from bar in source
where bar.Xzy == 123
select bar;
}
Intuitively, I would expect this to execute the "from...where...select" expression in the context of each source. However, I believe it will instead only execute the "from bar in ..." portion against the source, and instead execute the "where...select" portion as LINQ-to-Objects query. The net result is that all the rows of SomeTable will be retrieved from each source, instead of only those matching the "where" condition.
At first glance, my guess is that this is because the call to SelectMany causes the "source" expression to be implicitly converted to an IEnumerable<Bar>. I'm not sure what the implementation would look like, but wouldn't it make sense for it to accept Func<S, IQueryable<R>> instead, so that the where...select expression is passed to the IQueryable provider?
source.SomeTable? What happens if you change the return type offootoIQueryable<Bar>? - LeeIEnumerable<T, TResult>overload returnsIEnumerable<TResult>while theIQueryableoverload returns anIQueryable<T>. So your function would fail to compile if the return type were changed toIQueryable<Bar>and anIEnumerableoverload ofSelectManywere being chosen. - LeeIEnumerable<T, TResult>overload"? I think the type of the query expression inside the method is IQueryable<Bar>, which also implements IEnumerable<Bar>, so I'm not sure why it matters unless the caller of foo is going to pass the returned value to other LINQ methods. - Aaron