/// <summary> /// Creates a parallel query that projects each element of a sequence to an IEnumerable, flattens the resulting sequences into one sequence, and invokes a result selector function on each element therein. /// </summary> /// <typeparam name="TSource">The type of the elements of source.</typeparam> /// <typeparam name="TCol">The type of the intermediate elements collected by collectionSelector.</typeparam> /// <typeparam name="TResult">The type of the elements of the sequence returned by selector.</typeparam> /// <param name="query">A query whose values to project.</param> /// <param name="collectionSelector">A transform function to apply to each element of the input sequence.</param> /// <param name="resultSelector">A transform function to apply to each element of the intermediate sequence.</param> /// <returns>A parallel query whose elements are the result of invoking the one-to-many transform function on each element of the input sequence and the result selector function on each element therein.</returns> public static IParallelQueryExpr <IEnumerable <TResult> > SelectMany <TSource, TCol, TResult>(this IParallelQueryExpr <IEnumerable <TSource> > query, Expression <Func <TSource, IEnumerable <TCol> > > collectionSelector, Expression <Func <TSource, TCol, TResult> > resultSelector) { var paramExpr = collectionSelector.Parameters.Single(); var bodyExpr = collectionSelector.Body; var nested = Tuple.Create(paramExpr, CSharpExpressionOptimizer.ToQueryExpr(bodyExpr)); return(new ParallelQueryExpr <IEnumerable <TResult> >(QExpr.NewNestedQueryTransform(nested, resultSelector, query.Expr))); }