5 // Marek Safar (marek.safar@gmail.com)
6 // Alejandro Serrano "Serras" (trupill@yahoo.es)
7 // Jb Evain (jbevain@novell.com)
8 // Andreas Noever (andreas.noever@gmail.com)
10 // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Collections;
34 using System.Collections.Generic;
35 using System.Linq.Expressions;
36 using System.Reflection;
39 namespace System.Linq {
41 public static class Queryable {
43 static MethodInfo MakeGeneric (MethodBase method, params Type [] parameters)
45 return ((MethodInfo) method).MakeGenericMethod (parameters);
48 static Expression StaticCall (MethodInfo method, params Expression [] expressions)
50 return Expression.Call (null, method, expressions);
53 static TRet Execute<TRet, TSource> (this IQueryable<TSource> source, MethodBase current)
55 return source.Provider.Execute<TRet> (
57 MakeGeneric (current, typeof (TSource)),
63 public static TSource Aggregate<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, TSource, TSource>> func)
65 Check.SourceAndFunc (source, func);
66 return source.Provider.Execute<TSource> (
68 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
70 Expression.Quote (func)));
73 public static TAccumulate Aggregate<TSource, TAccumulate> (this IQueryable<TSource> source, TAccumulate seed, Expression<Func<TAccumulate, TSource, TAccumulate>> func)
75 Check.SourceAndFunc (source, func);
76 return source.Provider.Execute<TAccumulate> (
78 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TAccumulate)),
80 Expression.Constant (seed, typeof (TAccumulate)),
81 Expression.Quote (func)));
84 public static TResult Aggregate<TSource, TAccumulate, TResult> (this IQueryable<TSource> source, TAccumulate seed, Expression<Func<TAccumulate, TSource, TAccumulate>> func, Expression<Func<TAccumulate, TResult>> selector)
86 Check.SourceAndFuncAndSelector (source, func, selector);
87 return source.Provider.Execute<TResult> (
89 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TAccumulate), typeof (TResult)),
91 Expression.Constant (seed, typeof (TAccumulate)),
92 Expression.Quote (func),
93 Expression.Quote (selector)));
100 public static bool All<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
102 Check.SourceAndPredicate (source, predicate);
104 return source.Provider.Execute<bool> (
106 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
108 Expression.Quote (predicate)));
115 public static bool Any<TSource> (this IQueryable<TSource> source)
117 Check.Source (source);
119 return source.Provider.Execute<bool> (
121 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
125 public static bool Any<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
127 Check.SourceAndPredicate (source, predicate);
129 return source.Provider.Execute<bool> (
131 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
133 Expression.Quote (predicate)));
140 public static IQueryable<TElement> AsQueryable<TElement> (this IEnumerable<TElement> source)
143 throw new ArgumentNullException ("source");
145 var queryable = source as IQueryable<TElement>;
146 if (queryable != null)
149 return new QueryableEnumerable<TElement> (source);
152 public static IQueryable AsQueryable (this IEnumerable source)
155 throw new ArgumentNullException ("source");
157 var queryable = source as IQueryable;
158 if (queryable != null)
162 if (!source.GetType ().IsGenericImplementationOf (typeof (IEnumerable<>), out ienumerable))
163 throw new ArgumentException ("source is not IEnumerable<>");
165 return (IQueryable) Activator.CreateInstance (
166 typeof (QueryableEnumerable<>).MakeGenericType (ienumerable.GetFirstGenericArgument ()), source);
173 public static double Average (this IQueryable<int> source)
175 Check.Source (source);
177 return source.Provider.Execute<double>(
179 (MethodInfo) MethodBase.GetCurrentMethod (),
183 public static double? Average(this IQueryable<int?> source)
185 Check.Source (source);
187 return source.Provider.Execute<double?>(
189 (MethodInfo) MethodBase.GetCurrentMethod (),
193 public static double Average(this IQueryable<long> source)
195 Check.Source (source);
197 return source.Provider.Execute<double>(
199 (MethodInfo) MethodBase.GetCurrentMethod (),
203 public static double? Average(this IQueryable<long?> source)
205 Check.Source (source);
207 return source.Provider.Execute<double?>(
209 (MethodInfo) MethodBase.GetCurrentMethod (),
213 public static float Average(this IQueryable<float> source)
215 Check.Source (source);
217 return source.Provider.Execute<float>(
219 (MethodInfo) MethodBase.GetCurrentMethod (),
223 public static float? Average(this IQueryable<float?> source)
225 Check.Source (source);
227 return source.Provider.Execute<float?>(
229 (MethodInfo) MethodBase.GetCurrentMethod (),
233 public static double Average (this IQueryable<double> source)
235 Check.Source (source);
237 return source.Provider.Execute<double> (
239 (MethodInfo) MethodBase.GetCurrentMethod (),
243 public static double? Average (this IQueryable<double?> source)
245 Check.Source (source);
247 return source.Provider.Execute<double?> (
249 (MethodInfo) MethodBase.GetCurrentMethod (),
253 public static decimal Average(this IQueryable<decimal> source)
255 Check.Source (source);
257 return source.Provider.Execute<decimal>(
259 (MethodInfo) MethodBase.GetCurrentMethod (),
263 public static decimal? Average(this IQueryable<decimal?> source)
265 Check.Source (source);
267 return source.Provider.Execute<decimal?>(
269 (MethodInfo) MethodBase.GetCurrentMethod (),
273 public static double Average<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, int>> selector)
275 Check.SourceAndSelector (source, selector);
277 return source.Provider.Execute<double>(
279 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
281 Expression.Quote (selector)));
284 public static double? Average<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, int?>> selector)
286 Check.SourceAndSelector (source, selector);
288 return source.Provider.Execute<double?>(
290 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
292 Expression.Quote (selector)));
295 public static double Average<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, long>> selector)
297 Check.SourceAndSelector (source, selector);
299 return source.Provider.Execute<double>(
301 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
303 Expression.Quote (selector)));
306 public static double? Average<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, long?>> selector)
308 Check.SourceAndSelector (source, selector);
310 return source.Provider.Execute<double?>(
312 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
314 Expression.Quote (selector)));
317 public static float Average<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, float>> selector)
319 Check.SourceAndSelector (source, selector);
321 return source.Provider.Execute<float>(
323 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
325 Expression.Quote (selector)));
328 public static float? Average<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, float?>> selector)
330 Check.SourceAndSelector (source, selector);
332 return source.Provider.Execute<float?>(
334 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
336 Expression.Quote (selector)));
339 public static double Average<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, double>> selector)
341 Check.SourceAndSelector (source, selector);
343 return source.Provider.Execute<double> (
345 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
347 Expression.Quote (selector)));
350 public static double? Average<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, double?>> selector)
352 Check.SourceAndSelector (source, selector);
354 return source.Provider.Execute<double?> (
356 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
358 Expression.Quote (selector)));
361 public static decimal Average<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, decimal>> selector)
363 Check.SourceAndSelector (source, selector);
365 return source.Provider.Execute<decimal>(
367 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
369 Expression.Quote (selector)));
372 public static decimal? Average<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, decimal?>> selector)
374 Check.SourceAndSelector (source, selector);
376 return source.Provider.Execute<decimal?>(
378 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
380 Expression.Quote (selector)));
387 public static IQueryable<TResult> Cast<TResult> (this IQueryable source)
389 Check.Source (source);
391 return (IQueryable<TResult>) source.Provider.CreateQuery (
392 StaticCall (MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TResult)),
400 public static IQueryable<TSource> Concat<TSource> (this IQueryable<TSource> source1, IEnumerable<TSource> source2)
402 Check.Source1AndSource2 (source1, source2);
404 return source1.Provider.CreateQuery<TSource> (
406 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
408 Expression.Constant (source2, typeof (IEnumerable<TSource>))));
415 public static bool Contains<TSource> (this IQueryable<TSource> source, TSource item)
417 Check.Source (source);
419 return source.Provider.Execute<bool> (
421 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
423 Expression.Constant (item, typeof (TSource))));
426 public static bool Contains<TSource> (this IQueryable<TSource> source, TSource item, IEqualityComparer<TSource> comparer)
428 Check.Source (source);
430 return source.Provider.Execute<bool> (
432 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
434 Expression.Constant (item, typeof (TSource)),
435 Expression.Constant (comparer, typeof (IEqualityComparer<TSource>))));
442 public static int Count<TSource> (this IQueryable<TSource> source)
444 Check.Source (source);
446 return source.Execute<int, TSource> (MethodBase.GetCurrentMethod ());
449 public static int Count<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
451 Check.SourceAndPredicate (source, predicate);
453 return source.Provider.Execute<int> (
455 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
457 Expression.Quote (predicate)));
462 #region DefaultIfEmpty
464 public static IQueryable<TSource> DefaultIfEmpty<TSource> (this IQueryable<TSource> source)
466 Check.Source (source);
468 return source.Provider.CreateQuery<TSource> (
470 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
474 public static IQueryable<TSource> DefaultIfEmpty<TSource> (this IQueryable<TSource> source, TSource defaultValue)
476 Check.Source (source);
478 return source.Provider.CreateQuery<TSource> (
480 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
482 Expression.Constant (defaultValue, typeof (TSource))));
489 public static IQueryable<TSource> Distinct<TSource> (this IQueryable<TSource> source)
491 Check.Source (source);
493 return source.Provider.CreateQuery<TSource> (
495 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
499 public static IQueryable<TSource> Distinct<TSource> (this IQueryable<TSource> source, IEqualityComparer<TSource> comparer)
501 Check.Source (source);
503 return source.Provider.CreateQuery<TSource> (
505 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
507 Expression.Constant (comparer, typeof (IEqualityComparer<TSource>))));
514 public static TSource ElementAt<TSource> (this IQueryable<TSource> source, int index)
516 Check.Source (source);
518 return source.Provider.Execute<TSource> (
520 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
522 Expression.Constant (index)));
527 #region ElementAtOrDefault
529 public static TSource ElementAtOrDefault<TSource> (this IQueryable<TSource> source, int index)
531 Check.Source (source);
533 return source.Provider.Execute<TSource> (
535 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
537 Expression.Constant (index)));
544 public static IQueryable<TSource> Except<TSource> (this IQueryable<TSource> source1, IEnumerable<TSource> source2)
546 Check.Source1AndSource2 (source1, source2);
548 return source1.Provider.CreateQuery<TSource> (
550 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
552 Expression.Constant (source2, typeof (IEnumerable<TSource>))));
555 public static IQueryable<TSource> Except<TSource> (this IQueryable<TSource> source1, IEnumerable<TSource> source2, IEqualityComparer<TSource> comparer)
557 Check.Source1AndSource2 (source1, source2);
559 return source1.Provider.CreateQuery<TSource> (
561 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
563 Expression.Constant (source2, typeof (IEnumerable<TSource>)),
564 Expression.Constant (comparer, typeof (IEqualityComparer<TSource>))));
571 public static TSource First<TSource> (this IQueryable<TSource> source)
573 Check.Source (source);
575 return source.Provider.Execute<TSource> (
577 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
581 public static TSource First<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
583 Check.SourceAndPredicate (source, predicate);
585 return source.Provider.Execute<TSource> (
587 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
589 Expression.Quote (predicate)));
594 #region FirstOrDefault
596 public static TSource FirstOrDefault<TSource> (this IQueryable<TSource> source)
598 Check.Source (source);
600 return source.Provider.Execute<TSource> (
602 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
606 public static TSource FirstOrDefault<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
608 Check.SourceAndPredicate (source, predicate);
610 return source.Provider.Execute<TSource> (
612 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
614 Expression.Quote (predicate)));
621 public static IQueryable<IGrouping<TKey, TSource>> GroupBy<TSource, TKey> (this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
623 Check.SourceAndKeySelector (source, keySelector);
625 return source.Provider.CreateQuery<IGrouping<TKey, TSource>> (
627 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
629 Expression.Quote (keySelector)));
631 public static IQueryable<IGrouping<TKey, TSource>> GroupBy<TSource, TKey> (this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IEqualityComparer<TKey> comparer)
633 Check.SourceAndKeySelector (source, keySelector);
635 return source.Provider.CreateQuery<IGrouping<TKey, TSource>> (
637 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
639 Expression.Quote (keySelector),
640 Expression.Constant (comparer, typeof (IEqualityComparer<TKey>))));
642 public static IQueryable<IGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement> (this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector)
644 Check.SourceAndKeyElementSelectors (source, keySelector, elementSelector);
646 return source.Provider.CreateQuery<IGrouping<TKey, TElement>>(
648 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey), typeof (TElement)),
650 Expression.Quote (keySelector),
651 Expression.Quote (elementSelector)));
653 public static IQueryable<TResult> GroupBy<TSource, TKey, TResult> (this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TKey, IEnumerable<TSource>, TResult>> resultSelector)
655 Check.SourceAndKeyResultSelectors (source, keySelector, resultSelector);
657 return source.Provider.CreateQuery<TResult> (
659 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey), typeof (TResult)),
661 Expression.Quote (keySelector),
662 Expression.Quote (resultSelector)));
664 public static IQueryable<IGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement> (this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector, IEqualityComparer<TKey> comparer)
666 Check.SourceAndKeyElementSelectors (source, keySelector, elementSelector);
668 return source.Provider.CreateQuery<IGrouping<TKey, TElement>> (
670 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey), typeof (TElement)),
672 Expression.Quote (keySelector),
673 Expression.Quote (elementSelector),
674 Expression.Constant (comparer, typeof (IEqualityComparer<TKey>))));
676 public static IQueryable<TResult> GroupBy<TSource, TKey, TElement, TResult> (this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector, Expression<Func<TKey, IEnumerable<TElement>, TResult>> resultSelector)
678 Check.GroupBySelectors (source, keySelector, elementSelector, resultSelector);
680 return source.Provider.CreateQuery<TResult> (
682 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey), typeof (TElement), typeof (TResult)),
684 Expression.Quote (keySelector),
685 Expression.Quote (elementSelector),
686 Expression.Quote (resultSelector)));
689 public static IQueryable<TResult> GroupBy<TSource, TKey, TResult> (this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TKey, IEnumerable<TSource>, TResult>> resultSelector, IEqualityComparer<TKey> comparer)
691 Check.SourceAndKeyResultSelectors (source, keySelector, resultSelector);
693 return source.Provider.CreateQuery<TResult> (
695 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey), typeof (TResult)),
697 Expression.Quote (keySelector),
698 Expression.Quote (resultSelector),
699 Expression.Constant (comparer, typeof (IEqualityComparer<TKey>))));
701 public static IQueryable<TResult> GroupBy<TSource, TKey, TElement, TResult> (this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector, Expression<Func<TKey, IEnumerable<TElement>, TResult>> resultSelector, IEqualityComparer<TKey> comparer)
703 Check.GroupBySelectors (source, keySelector, elementSelector, resultSelector);
705 return source.Provider.CreateQuery<TResult> (
707 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey), typeof (TElement), typeof (TResult)),
709 Expression.Quote (keySelector),
710 Expression.Quote (elementSelector),
711 Expression.Quote (resultSelector),
712 Expression.Constant (comparer, typeof (IEqualityComparer<TKey>))));
718 public static IQueryable<TResult> GroupJoin<TOuter, TInner, TKey, TResult> (this IQueryable<TOuter> outer, IEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, IEnumerable<TInner>, TResult>> resultSelector)
721 throw new ArgumentNullException ("outer");
723 throw new ArgumentNullException ("inner");
724 if (outerKeySelector == null)
725 throw new ArgumentNullException ("outerKeySelector");
726 if (innerKeySelector == null)
727 throw new ArgumentNullException ("innerKeySelector");
728 if (resultSelector == null)
729 throw new ArgumentNullException ("resultSelector");
731 return outer.Provider.CreateQuery<TResult> (
733 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TOuter), typeof (TInner), typeof (TKey), typeof (TResult)),
735 Expression.Constant (inner, typeof (IEnumerable<TInner>)),
736 Expression.Quote (outerKeySelector),
737 Expression.Quote (innerKeySelector),
738 Expression.Quote (resultSelector)));
741 public static IQueryable<TResult> GroupJoin<TOuter, TInner, TKey, TResult> (this IQueryable<TOuter> outer, IEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, IEnumerable<TInner>, TResult>> resultSelector, IEqualityComparer<TKey> comparer)
744 throw new ArgumentNullException ("outer");
746 throw new ArgumentNullException ("inner");
747 if (outerKeySelector == null)
748 throw new ArgumentNullException ("outerKeySelector");
749 if (innerKeySelector == null)
750 throw new ArgumentNullException ("innerKeySelector");
751 if (resultSelector == null)
752 throw new ArgumentNullException ("resultSelector");
754 return outer.Provider.CreateQuery<TResult> (
756 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TOuter), typeof (TInner), typeof (TKey), typeof (TResult)),
758 Expression.Constant (inner, typeof (IEnumerable<TInner>)),
759 Expression.Quote (outerKeySelector),
760 Expression.Quote (innerKeySelector),
761 Expression.Quote (resultSelector),
762 Expression.Constant (comparer)));
769 public static IQueryable<TSource> Intersect<TSource> (this IQueryable<TSource> source1, IEnumerable<TSource> source2)
771 Check.Source1AndSource2 (source1, source2);
773 return source1.Provider.CreateQuery<TSource> (
775 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
777 Expression.Constant (source2, typeof (IEnumerable<TSource>))));
780 public static IQueryable<TSource> Intersect<TSource> (this IQueryable<TSource> source1, IEnumerable<TSource> source2, IEqualityComparer<TSource> comparer)
782 Check.Source1AndSource2 (source1, source2);
784 return source1.Provider.CreateQuery<TSource> (
786 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
788 Expression.Constant (source2, typeof (IEnumerable<TSource>)),
789 Expression.Constant (comparer, typeof (IEqualityComparer<TSource>))));
796 public static IQueryable<TResult> Join<TOuter, TInner, TKey, TResult> (this IQueryable<TOuter> outer, IEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, TInner, TResult>> resultSelector)
798 Check.JoinSelectors (outer, inner, outerKeySelector, innerKeySelector, resultSelector);
800 return outer.Provider.CreateQuery<TResult> (
802 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TOuter), typeof (TInner), typeof (TKey), typeof (TResult)),
804 Expression.Constant (inner, typeof (IEnumerable<TInner>)),
805 Expression.Quote (outerKeySelector),
806 Expression.Quote (innerKeySelector),
807 Expression.Quote (resultSelector)));
810 public static IQueryable<TResult> Join<TOuter, TInner, TKey, TResult> (this IQueryable<TOuter> outer, IEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, TInner, TResult>> resultSelector, IEqualityComparer<TKey> comparer)
812 Check.JoinSelectors (outer, inner, outerKeySelector, innerKeySelector, resultSelector);
814 return outer.Provider.CreateQuery<TResult> (
816 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TOuter), typeof (TInner), typeof (TKey), typeof (TResult)),
818 Expression.Constant (inner, typeof (IEnumerable<TInner>)),
819 Expression.Quote (outerKeySelector),
820 Expression.Quote (innerKeySelector),
821 Expression.Quote (resultSelector),
822 Expression.Constant (comparer, typeof (IEqualityComparer<TKey>))));
830 public static TSource Last<TSource> (this IQueryable<TSource> source)
832 Check.Source (source);
834 return source.Provider.Execute<TSource> (
836 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
840 public static TSource Last<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
842 Check.SourceAndPredicate (source, predicate);
844 return source.Provider.Execute<TSource> (
846 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
848 Expression.Quote (predicate)));
853 #region LastOrDefault
855 public static TSource LastOrDefault<TSource> (this IQueryable<TSource> source)
857 Check.Source (source);
859 return source.Provider.Execute<TSource> (
861 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
865 public static TSource LastOrDefault<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
867 Check.SourceAndPredicate (source, predicate);
869 return source.Provider.Execute<TSource> (
871 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
873 Expression.Quote (predicate)));
880 public static long LongCount<TSource> (this IQueryable<TSource> source)
882 Check.Source (source);
884 return source.Execute<long, TSource> (MethodBase.GetCurrentMethod ());
887 public static long LongCount<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
889 Check.SourceAndPredicate (source, predicate);
891 return source.Provider.Execute<long> (
893 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
895 Expression.Quote (predicate)));
902 public static TSource Max<TSource> (this IQueryable<TSource> source)
904 Check.Source (source);
906 return source.Provider.Execute<TSource> (
908 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
912 public static TResult Max<TSource, TResult> (this IQueryable<TSource> source, Expression<Func<TSource, TResult>> selector)
914 Check.Source (source);
916 return source.Provider.Execute<TResult> (
918 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TResult)),
920 Expression.Quote (selector)));
928 public static TSource Min<TSource> (this IQueryable<TSource> source)
930 Check.Source (source);
932 return source.Provider.Execute<TSource> (
934 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
938 public static TResult Min<TSource, TResult> (this IQueryable<TSource> source, Expression<Func<TSource, TResult>> selector)
940 Check.SourceAndSelector (source, selector);
942 return source.Provider.Execute<TResult> (
944 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TResult)),
946 Expression.Quote (selector)));
954 public static IQueryable<TResult> OfType<TResult> (this IQueryable source)
956 Check.Source (source);
958 return (IQueryable<TResult>) source.Provider.CreateQuery (
960 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TResult)),
968 public static IOrderedQueryable<TSource> OrderBy<TSource, TKey> (this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
970 Check.SourceAndKeySelector (source, keySelector);
972 return (IOrderedQueryable<TSource>) source.Provider.CreateQuery<TSource> (
974 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
976 Expression.Quote (keySelector)));
979 public static IOrderedQueryable<TSource> OrderBy<TSource, TKey> (this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey> comparer)
981 Check.SourceAndKeySelector (source, keySelector);
983 return (IOrderedQueryable<TSource>) source.Provider.CreateQuery<TSource> (
985 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
987 Expression.Quote (keySelector),
988 Expression.Constant (comparer, typeof (IComparer<TKey>))));
993 #region OrderByDescending
995 public static IOrderedQueryable<TSource> OrderByDescending<TSource, TKey> (this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
997 Check.SourceAndKeySelector (source, keySelector);
999 return (IOrderedQueryable<TSource>) source.Provider.CreateQuery<TSource> (
1001 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
1003 Expression.Quote (keySelector)));
1006 public static IOrderedQueryable<TSource> OrderByDescending<TSource, TKey> (this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey> comparer)
1008 Check.SourceAndKeySelector (source, keySelector);
1010 return (IOrderedQueryable<TSource>) source.Provider.CreateQuery<TSource> (
1012 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
1014 Expression.Quote (keySelector),
1015 Expression.Constant (comparer, typeof (IComparer<TKey>))));
1022 public static IQueryable<TSource> Reverse<TSource> (this IQueryable<TSource> source)
1024 Check.Source (source);
1026 return source.Provider.CreateQuery<TSource> (
1028 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1029 source.Expression));
1036 public static IQueryable<TResult> Select<TSource, TResult> (this IQueryable<TSource> source, Expression<Func<TSource, TResult>> selector)
1038 Check.SourceAndSelector (source, selector);
1040 return source.Provider.CreateQuery<TResult> (
1042 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TResult)),
1044 Expression.Quote (selector)));
1047 public static IQueryable<TResult> Select<TSource, TResult> (this IQueryable<TSource> source, Expression<Func<TSource, int, TResult>> selector)
1049 Check.SourceAndSelector (source, selector);
1051 return source.Provider.CreateQuery<TResult> (
1053 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TResult)),
1055 Expression.Quote (selector)));
1062 public static IQueryable<TResult> SelectMany<TSource, TResult> (this IQueryable<TSource> source, Expression<Func<TSource, IEnumerable<TResult>>> selector)
1064 Check.SourceAndSelector (source, selector);
1066 return source.Provider.CreateQuery<TResult> (
1068 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TResult)),
1070 Expression.Quote (selector)));
1073 public static IQueryable<TResult> SelectMany<TSource, TResult> (this IQueryable<TSource> source, Expression<Func<TSource, int, IEnumerable<TResult>>> selector)
1075 Check.SourceAndSelector (source, selector);
1077 return source.Provider.CreateQuery<TResult> (
1079 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TResult)),
1081 Expression.Quote (selector)));
1084 public static IQueryable<TResult> SelectMany<TSource, TCollection, TResult> (this IQueryable<TSource> source, Expression<Func<TSource, int, IEnumerable<TCollection>>> collectionSelector, Expression<Func<TSource, TCollection, TResult>> resultSelector)
1086 Check.SourceAndCollectionSelectorAndResultSelector (source, collectionSelector, resultSelector);
1088 return source.Provider.CreateQuery<TResult> (
1090 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TCollection), typeof (TResult)),
1092 Expression.Quote (collectionSelector),
1093 Expression.Quote (resultSelector)));
1096 public static IQueryable<TResult> SelectMany<TSource, TCollection, TResult> (this IQueryable<TSource> source, Expression<Func<TSource, IEnumerable<TCollection>>> collectionSelector, Expression<Func<TSource, TCollection, TResult>> resultSelector)
1098 Check.SourceAndCollectionSelectorAndResultSelector (source, collectionSelector, resultSelector);
1100 return source.Provider.CreateQuery<TResult> (
1102 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TCollection), typeof (TResult)),
1104 Expression.Quote (collectionSelector),
1105 Expression.Quote (resultSelector)));
1110 #region SequenceEqual
1112 public static bool SequenceEqual<TSource> (this IQueryable<TSource> source1, IEnumerable<TSource> source2)
1114 Check.Source1AndSource2 (source1, source2);
1116 return source1.Provider.Execute<bool> (
1118 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1120 Expression.Constant (source2, typeof (IEnumerable<TSource>))));
1123 public static bool SequenceEqual<TSource> (this IQueryable<TSource> source1, IEnumerable<TSource> source2, IEqualityComparer<TSource> comparer)
1125 Check.Source1AndSource2 (source1, source2);
1127 return source1.Provider.Execute<bool> (
1129 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1131 Expression.Constant (source2, typeof (IEnumerable<TSource>)),
1132 Expression.Constant (comparer, typeof (IEqualityComparer<TSource>))));
1139 public static TSource Single<TSource> (this IQueryable<TSource> source)
1141 Check.Source (source);
1143 return source.Provider.Execute<TSource> (
1145 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1146 source.Expression));
1149 public static TSource Single<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
1151 Check.SourceAndPredicate (source, predicate);
1153 return source.Provider.Execute<TSource> (
1155 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1157 Expression.Quote (predicate)));
1162 #region SingleOrDefault
1164 public static TSource SingleOrDefault<TSource> (this IQueryable<TSource> source)
1166 Check.Source (source);
1168 return source.Provider.Execute<TSource> (
1170 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1171 source.Expression));
1174 public static TSource SingleOrDefault<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
1176 Check.SourceAndPredicate (source, predicate);
1178 return source.Provider.Execute<TSource> (
1180 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1182 Expression.Quote (predicate)));
1189 public static IQueryable<TSource> Skip<TSource> (this IQueryable<TSource> source, int count)
1191 Check.Source (source);
1193 return source.Provider.CreateQuery<TSource> (
1195 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1197 Expression.Constant (count)));
1204 public static IQueryable<TSource> SkipWhile<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
1206 Check.SourceAndPredicate (source, predicate);
1208 return source.Provider.CreateQuery<TSource> (
1210 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1212 Expression.Quote (predicate)));
1215 public static IQueryable<TSource> SkipWhile<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, int, bool>> predicate)
1217 Check.SourceAndPredicate (source, predicate);
1219 return source.Provider.CreateQuery<TSource> (
1221 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1223 Expression.Quote (predicate)));
1232 public static int Sum<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, int>> selector)
1234 Check.SourceAndSelector (source, selector);
1236 return source.Provider.Execute<int> (
1238 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1240 Expression.Quote (selector)));
1243 public static int? Sum<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, int?>> selector)
1245 Check.SourceAndSelector (source, selector);
1247 return source.Provider.Execute<int?> (
1249 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1251 Expression.Quote (selector)));
1254 public static long Sum<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, long>> selector)
1256 Check.SourceAndSelector (source, selector);
1258 return source.Provider.Execute<long> (
1260 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1262 Expression.Quote (selector)));
1265 public static long? Sum<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, long?>> selector)
1267 Check.SourceAndSelector (source, selector);
1269 return source.Provider.Execute<long?> (
1271 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1273 Expression.Quote (selector)));
1276 public static float Sum<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, float>> selector)
1278 Check.SourceAndSelector (source, selector);
1280 return source.Provider.Execute<float> (
1282 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1284 Expression.Quote (selector)));
1287 public static float? Sum<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, float?>> selector)
1289 Check.SourceAndSelector (source, selector);
1291 return source.Provider.Execute<float?> (
1293 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1295 Expression.Quote (selector)));
1298 public static double Sum<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, double>> selector)
1300 Check.SourceAndSelector (source, selector);
1302 return source.Provider.Execute<double> (
1304 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1306 Expression.Quote (selector)));
1309 public static double? Sum<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, double?>> selector)
1311 Check.SourceAndSelector (source, selector);
1313 return source.Provider.Execute<double?> (
1315 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1317 Expression.Quote (selector)));
1320 public static decimal Sum<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, decimal>> selector)
1322 Check.SourceAndSelector (source, selector);
1324 return source.Provider.Execute<decimal> (
1326 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1328 Expression.Quote (selector)));
1331 public static decimal? Sum<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, decimal?>> selector)
1333 Check.SourceAndSelector (source, selector);
1335 return source.Provider.Execute<decimal?> (
1337 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1339 Expression.Quote (selector)));
1342 public static int Sum (this IQueryable<int> source)
1344 Check.Source (source);
1346 return source.Provider.Execute<int> (
1348 (MethodInfo) MethodBase.GetCurrentMethod (),
1349 source.Expression));
1352 public static int? Sum (this IQueryable<int?> source)
1354 Check.Source (source);
1356 return source.Provider.Execute<int?> (
1358 (MethodInfo) MethodBase.GetCurrentMethod (),
1359 source.Expression));
1364 public static long Sum (this IQueryable<long> source)
1366 Check.Source (source);
1368 return source.Provider.Execute<long> (
1370 (MethodInfo) MethodBase.GetCurrentMethod (),
1371 source.Expression));
1376 public static long? Sum (this IQueryable<long?> source)
1378 Check.Source (source);
1380 return source.Provider.Execute<long?> (
1382 (MethodInfo) MethodBase.GetCurrentMethod (),
1383 source.Expression));
1386 public static float Sum (this IQueryable<float> source)
1388 Check.Source (source);
1390 return source.Provider.Execute<float> (
1392 (MethodInfo) MethodBase.GetCurrentMethod (),
1393 source.Expression));
1396 public static float? Sum (this IQueryable<float?> source)
1398 Check.Source (source);
1400 return source.Provider.Execute<float?> (
1402 (MethodInfo) MethodBase.GetCurrentMethod (),
1403 source.Expression));
1407 public static double Sum (this IQueryable<double> source)
1409 Check.Source (source);
1411 return source.Provider.Execute<double> (
1413 (MethodInfo) MethodBase.GetCurrentMethod (),
1414 source.Expression));
1419 public static double? Sum (this IQueryable<double?> source)
1421 Check.Source (source);
1423 return source.Provider.Execute<double?> (
1425 (MethodInfo) MethodBase.GetCurrentMethod (),
1426 source.Expression));
1430 public static decimal Sum (this IQueryable<decimal> source)
1432 Check.Source (source);
1434 return source.Provider.Execute<decimal> (
1436 (MethodInfo) MethodBase.GetCurrentMethod (),
1437 source.Expression));
1442 public static decimal? Sum (this IQueryable<decimal?> source)
1444 Check.Source (source);
1446 return source.Provider.Execute<decimal?> (
1448 (MethodInfo) MethodBase.GetCurrentMethod (),
1449 source.Expression));
1458 public static IQueryable<TSource> Take<TSource> (this IQueryable<TSource> source, int count)
1460 Check.Source (source);
1462 return source.Provider.CreateQuery<TSource> (
1464 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1466 Expression.Constant (count)));
1473 public static IQueryable<TSource> TakeWhile<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
1475 Check.SourceAndPredicate (source, predicate);
1477 return source.Provider.CreateQuery<TSource> (
1479 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1481 Expression.Quote (predicate)));
1484 public static IQueryable<TSource> TakeWhile<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, int, bool>> predicate)
1486 Check.SourceAndPredicate (source, predicate);
1488 return source.Provider.CreateQuery<TSource> (
1490 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1492 Expression.Quote (predicate)));
1499 public static IOrderedQueryable<TSource> ThenBy<TSource, TKey> (this IOrderedQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
1501 Check.SourceAndKeySelector (source, keySelector);
1503 return (IOrderedQueryable<TSource>) source.Provider.CreateQuery (
1505 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
1507 Expression.Quote (keySelector)));
1510 public static IOrderedQueryable<TSource> ThenBy<TSource, TKey> (this IOrderedQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey> comparer)
1512 Check.SourceAndKeySelector (source, keySelector);
1514 return (IOrderedQueryable<TSource>) source.Provider.CreateQuery (
1516 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
1518 Expression.Quote (keySelector),
1519 Expression.Constant (comparer, typeof (IComparer<TKey>))));
1524 #region ThenByDescending
1526 public static IOrderedQueryable<TSource> ThenByDescending<TSource, TKey> (this IOrderedQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
1528 Check.SourceAndKeySelector (source, keySelector);
1530 return (IOrderedQueryable<TSource>) source.Provider.CreateQuery (
1532 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
1534 Expression.Quote (keySelector)));
1537 public static IOrderedQueryable<TSource> ThenByDescending<TSource, TKey> (this IOrderedQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, IComparer<TKey> comparer)
1539 Check.SourceAndKeySelector (source, keySelector);
1541 return (IOrderedQueryable<TSource>) source.Provider.CreateQuery (
1543 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource), typeof (TKey)),
1545 Expression.Quote (keySelector),
1546 Expression.Constant (comparer, typeof (IComparer<TKey>))));
1553 public static IQueryable<TSource> Union<TSource> (this IQueryable<TSource> source1, IEnumerable<TSource> source2)
1555 Check.Source1AndSource2 (source1, source2);
1557 return source1.Provider.CreateQuery<TSource> (
1559 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1561 Expression.Constant (source2, typeof (IEnumerable<TSource>))));
1564 public static IQueryable<TSource> Union<TSource>(this IQueryable<TSource> source1, IEnumerable<TSource> source2, IEqualityComparer<TSource> comparer)
1566 Check.Source1AndSource2 (source1, source2);
1568 return source1.Provider.CreateQuery<TSource> (
1570 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1572 Expression.Constant (source2, typeof (IEnumerable<TSource>)),
1573 Expression.Constant (comparer, typeof (IEqualityComparer<TSource>))));
1581 public static IQueryable<TSource> Where<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
1583 Check.SourceAndPredicate (source, predicate);
1585 return source.Provider.CreateQuery<TSource> (
1587 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1589 Expression.Quote (predicate)));
1592 public static IQueryable<TSource> Where<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, int, bool>> predicate)
1594 Check.SourceAndPredicate (source, predicate);
1596 return source.Provider.CreateQuery<TSource> (
1598 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
1600 Expression.Quote (predicate)));
1606 #if NET_4_0 || MOBILE
1609 public static IQueryable<TResult> Zip<TFirst, TSecond, TResult> (this IQueryable<TFirst> source1, IEnumerable<TSecond> source2, Expression<Func<TFirst, TSecond, TResult>> resultSelector)
1611 Check.Source1AndSource2 (source1, source2);
1612 if (resultSelector == null)
1613 throw new ArgumentNullException ("resultSelector");
1615 return source1.Provider.CreateQuery<TResult> (
1617 MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TFirst), typeof (TSecond), typeof (TResult)),
1619 Expression.Quote (resultSelector)));