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
),
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
),
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)
161 var type
= source
.GetType ();
163 if (!type
.IsGenericImplementationOf (typeof (IEnumerable
<>)))
164 throw new ArgumentException ("source is not IEnumerable<>");
166 return (IQueryable
) Activator
.CreateInstance (
167 typeof (QueryableEnumerable
<>).MakeGenericType (type
.GetFirstGenericArgument ()), source
);
174 public static double Average (this IQueryable
<int> source
)
176 Check
.Source (source
);
178 return source
.Provider
.Execute
<double>(
180 (MethodInfo
) MethodBase
.GetCurrentMethod (),
184 public static double? Average(this IQueryable
<int?> source
)
186 Check
.Source (source
);
188 return source
.Provider
.Execute
<double?>(
190 (MethodInfo
) MethodBase
.GetCurrentMethod (),
194 public static double Average(this IQueryable
<long> source
)
196 Check
.Source (source
);
198 return source
.Provider
.Execute
<double>(
200 (MethodInfo
) MethodBase
.GetCurrentMethod (),
204 public static double? Average(this IQueryable
<long?> source
)
206 Check
.Source (source
);
208 return source
.Provider
.Execute
<double?>(
210 (MethodInfo
) MethodBase
.GetCurrentMethod (),
214 public static float Average(this IQueryable
<float> source
)
216 Check
.Source (source
);
218 return source
.Provider
.Execute
<float>(
220 (MethodInfo
) MethodBase
.GetCurrentMethod (),
224 public static float? Average(this IQueryable
<float?> source
)
226 Check
.Source (source
);
228 return source
.Provider
.Execute
<float?>(
230 (MethodInfo
) MethodBase
.GetCurrentMethod (),
234 public static double Average (this IQueryable
<double> source
)
236 Check
.Source (source
);
238 return source
.Provider
.Execute
<double> (
240 (MethodInfo
) MethodBase
.GetCurrentMethod (),
244 public static double? Average (this IQueryable
<double?> source
)
246 Check
.Source (source
);
248 return source
.Provider
.Execute
<double?> (
250 (MethodInfo
) MethodBase
.GetCurrentMethod (),
254 public static decimal Average(this IQueryable
<decimal> source
)
256 Check
.Source (source
);
258 return source
.Provider
.Execute
<decimal>(
260 (MethodInfo
) MethodBase
.GetCurrentMethod (),
264 public static decimal? Average(this IQueryable
<decimal?> source
)
266 Check
.Source (source
);
268 return source
.Provider
.Execute
<decimal?>(
270 (MethodInfo
) MethodBase
.GetCurrentMethod (),
274 public static double Average
<TSource
>(this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, int>> selector
)
276 Check
.SourceAndSelector (source
, selector
);
278 return source
.Provider
.Execute
<double>(
280 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
282 Expression
.Quote (selector
)));
285 public static double? Average
<TSource
>(this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, int?>> selector
)
287 Check
.SourceAndSelector (source
, selector
);
289 return source
.Provider
.Execute
<double?>(
291 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
293 Expression
.Quote (selector
)));
296 public static double Average
<TSource
>(this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, long>> selector
)
298 Check
.SourceAndSelector (source
, selector
);
300 return source
.Provider
.Execute
<double>(
302 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
304 Expression
.Quote (selector
)));
307 public static double? Average
<TSource
>(this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, long?>> selector
)
309 Check
.SourceAndSelector (source
, selector
);
311 return source
.Provider
.Execute
<double?>(
313 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
315 Expression
.Quote (selector
)));
318 public static float Average
<TSource
>(this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, float>> selector
)
320 Check
.SourceAndSelector (source
, selector
);
322 return source
.Provider
.Execute
<float>(
324 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
326 Expression
.Quote (selector
)));
329 public static float? Average
<TSource
>(this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, float?>> selector
)
331 Check
.SourceAndSelector (source
, selector
);
333 return source
.Provider
.Execute
<float?>(
335 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
337 Expression
.Quote (selector
)));
340 public static double Average
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, double>> selector
)
342 Check
.SourceAndSelector (source
, selector
);
344 return source
.Provider
.Execute
<double> (
346 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
348 Expression
.Quote (selector
)));
351 public static double? Average
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, double?>> selector
)
353 Check
.SourceAndSelector (source
, selector
);
355 return source
.Provider
.Execute
<double?> (
357 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
359 Expression
.Quote (selector
)));
362 public static decimal Average
<TSource
>(this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, decimal>> selector
)
364 Check
.SourceAndSelector (source
, selector
);
366 return source
.Provider
.Execute
<decimal>(
368 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
370 Expression
.Quote (selector
)));
373 public static decimal? Average
<TSource
>(this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, decimal?>> selector
)
375 Check
.SourceAndSelector (source
, selector
);
377 return source
.Provider
.Execute
<decimal?>(
379 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
381 Expression
.Quote (selector
)));
388 public static IQueryable
<TResult
> Cast
<TResult
> (this IQueryable source
)
390 Check
.Source (source
);
392 return (IQueryable
<TResult
>) source
.Provider
.CreateQuery (
393 StaticCall (MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TResult
)),
401 public static IQueryable
<TSource
> Concat
<TSource
> (this IQueryable
<TSource
> source1
, IEnumerable
<TSource
> source2
)
403 Check
.Source1AndSource2 (source1
, source2
);
405 return source1
.Provider
.CreateQuery
<TSource
> (
407 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
409 Expression
.Constant (source2
)));
416 public static bool Contains
<TSource
> (this IQueryable
<TSource
> source
, TSource item
)
418 Check
.Source (source
);
420 return source
.Provider
.Execute
<bool> (
422 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
424 Expression
.Constant (item
)));
427 public static bool Contains
<TSource
> (this IQueryable
<TSource
> source
, TSource item
, IEqualityComparer
<TSource
> comparer
)
429 Check
.Source (source
);
431 return source
.Provider
.Execute
<bool> (
433 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
435 Expression
.Constant (item
),
436 Expression
.Constant (comparer
)));
443 public static int Count
<TSource
> (this IQueryable
<TSource
> source
)
445 Check
.Source (source
);
447 return source
.Execute
<int, TSource
> (MethodBase
.GetCurrentMethod ());
450 public static int Count
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, bool>> predicate
)
452 Check
.SourceAndPredicate (source
, predicate
);
454 return source
.Provider
.Execute
<int> (
456 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
458 Expression
.Quote (predicate
)));
463 #region DefaultIfEmpty
465 public static IQueryable
<TSource
> DefaultIfEmpty
<TSource
> (this IQueryable
<TSource
> source
)
467 Check
.Source (source
);
469 return source
.Provider
.CreateQuery
<TSource
> (
471 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
475 public static IQueryable
<TSource
> DefaultIfEmpty
<TSource
> (this IQueryable
<TSource
> source
, TSource defaultValue
)
477 Check
.Source (source
);
479 return source
.Provider
.CreateQuery
<TSource
> (
481 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
483 Expression
.Constant (defaultValue
)));
490 public static IQueryable
<TSource
> Distinct
<TSource
> (this IQueryable
<TSource
> source
)
492 Check
.Source (source
);
494 return source
.Provider
.CreateQuery
<TSource
> (
496 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
500 public static IQueryable
<TSource
> Distinct
<TSource
> (this IQueryable
<TSource
> source
, IEqualityComparer
<TSource
> comparer
)
502 Check
.Source (source
);
504 return source
.Provider
.CreateQuery
<TSource
> (
506 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
508 Expression
.Constant (comparer
)));
515 public static TSource ElementAt
<TSource
> (this IQueryable
<TSource
> source
, int index
)
517 Check
.Source (source
);
519 return source
.Provider
.Execute
<TSource
> (
521 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
523 Expression
.Constant (index
)));
528 #region ElementAtOrDefault
530 public static TSource ElementAtOrDefault
<TSource
> (this IQueryable
<TSource
> source
, int index
)
532 Check
.Source (source
);
534 return source
.Provider
.Execute
<TSource
> (
536 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
538 Expression
.Constant (index
)));
545 public static IQueryable
<TSource
> Except
<TSource
> (this IQueryable
<TSource
> source1
, IEnumerable
<TSource
> source2
)
547 Check
.Source1AndSource2 (source1
, source2
);
549 return source1
.Provider
.CreateQuery
<TSource
> (
551 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
553 Expression
.Constant (source2
)));
556 public static IQueryable
<TSource
> Except
<TSource
> (this IQueryable
<TSource
> source1
, IEnumerable
<TSource
> source2
, IEqualityComparer
<TSource
> comparer
)
558 Check
.Source1AndSource2 (source1
, source2
);
560 return source1
.Provider
.CreateQuery
<TSource
> (
562 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
564 Expression
.Constant (source2
),
565 Expression
.Constant (comparer
)));
572 public static TSource First
<TSource
> (this IQueryable
<TSource
> source
)
574 Check
.Source (source
);
576 return source
.Provider
.Execute
<TSource
> (
578 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
582 public static TSource First
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, bool>> predicate
)
584 Check
.SourceAndPredicate (source
, predicate
);
586 return source
.Provider
.Execute
<TSource
> (
588 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
590 Expression
.Quote (predicate
)));
595 #region FirstOrDefault
597 public static TSource FirstOrDefault
<TSource
> (this IQueryable
<TSource
> source
)
599 Check
.Source (source
);
601 return source
.Provider
.Execute
<TSource
> (
603 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
607 public static TSource FirstOrDefault
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, bool>> predicate
)
609 Check
.SourceAndPredicate (source
, predicate
);
611 return source
.Provider
.Execute
<TSource
> (
613 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
615 Expression
.Quote (predicate
)));
622 public static IQueryable
<IGrouping
<TKey
, TSource
>> GroupBy
<TSource
, TKey
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, TKey
>> keySelector
)
624 Check
.SourceAndKeySelector (source
, keySelector
);
626 return source
.Provider
.CreateQuery
<IGrouping
<TKey
, TSource
>> (
628 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
)),
630 Expression
.Quote (keySelector
)));
632 public static IQueryable
<IGrouping
<TKey
, TSource
>> GroupBy
<TSource
, TKey
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, TKey
>> keySelector
, IEqualityComparer
<TKey
> comparer
)
634 Check
.SourceAndKeySelector (source
, keySelector
);
636 return source
.Provider
.CreateQuery
<IGrouping
<TKey
, TSource
>> (
638 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
)),
640 Expression
.Quote (keySelector
),
641 Expression
.Constant (comparer
)));
643 public static IQueryable
<IGrouping
<TKey
, TElement
>> GroupBy
<TSource
, TKey
, TElement
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, TKey
>> keySelector
, Expression
<Func
<TSource
, TElement
>> elementSelector
)
645 Check
.SourceAndKeyElementSelectors (source
, keySelector
, elementSelector
);
647 return source
.Provider
.CreateQuery
<IGrouping
<TKey
, TElement
>>(
649 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
), typeof (TElement
)),
651 Expression
.Quote (keySelector
),
652 Expression
.Quote (elementSelector
)));
654 public static IQueryable
<TResult
> GroupBy
<TSource
, TKey
, TResult
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, TKey
>> keySelector
, Expression
<Func
<TKey
, IEnumerable
<TSource
>, TResult
>> resultSelector
)
656 Check
.SourceAndKeyResultSelectors (source
, keySelector
, resultSelector
);
658 return source
.Provider
.CreateQuery
<TResult
> (
660 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
), typeof (TResult
)),
662 Expression
.Quote (keySelector
),
663 Expression
.Quote (resultSelector
)));
665 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
)
667 Check
.SourceAndKeyElementSelectors (source
, keySelector
, elementSelector
);
669 return source
.Provider
.CreateQuery
<IGrouping
<TKey
, TElement
>> (
671 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
), typeof (TElement
)),
673 Expression
.Quote (keySelector
),
674 Expression
.Quote (elementSelector
),
675 Expression
.Constant (comparer
)));
677 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
)
679 Check
.GroupBySelectors (source
, keySelector
, elementSelector
, resultSelector
);
681 return source
.Provider
.CreateQuery
<TResult
> (
683 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
), typeof (TElement
), typeof (TResult
)),
685 Expression
.Quote (keySelector
),
686 Expression
.Quote (elementSelector
),
687 Expression
.Quote (resultSelector
)));
690 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
)
692 Check
.SourceAndKeyResultSelectors (source
, keySelector
, resultSelector
);
694 return source
.Provider
.CreateQuery
<TResult
> (
696 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
), typeof (TResult
)),
698 Expression
.Quote (keySelector
),
699 Expression
.Quote (resultSelector
),
700 Expression
.Constant (comparer
)));
702 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
)
704 Check
.GroupBySelectors (source
, keySelector
, elementSelector
, resultSelector
);
706 return source
.Provider
.CreateQuery
<TResult
> (
708 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
), typeof (TElement
), typeof (TResult
)),
710 Expression
.Quote (keySelector
),
711 Expression
.Quote (elementSelector
),
712 Expression
.Quote (resultSelector
),
713 Expression
.Constant (comparer
)));
719 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
)
722 throw new ArgumentNullException ("outer");
724 throw new ArgumentNullException ("inner");
725 if (outerKeySelector
== null)
726 throw new ArgumentNullException ("outerKeySelector");
727 if (innerKeySelector
== null)
728 throw new ArgumentNullException ("innerKeySelector");
729 if (resultSelector
== null)
730 throw new ArgumentNullException ("resultSelector");
732 return outer
.Provider
.CreateQuery
<TResult
> (
734 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TOuter
), typeof (TInner
), typeof (TKey
), typeof (TResult
)),
736 Expression
.Constant (inner
),
737 Expression
.Quote (outerKeySelector
),
738 Expression
.Quote (innerKeySelector
),
739 Expression
.Quote (resultSelector
)));
742 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
)
745 throw new ArgumentNullException ("outer");
747 throw new ArgumentNullException ("inner");
748 if (outerKeySelector
== null)
749 throw new ArgumentNullException ("outerKeySelector");
750 if (innerKeySelector
== null)
751 throw new ArgumentNullException ("innerKeySelector");
752 if (resultSelector
== null)
753 throw new ArgumentNullException ("resultSelector");
755 return outer
.Provider
.CreateQuery
<TResult
> (
757 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TOuter
), typeof (TInner
), typeof (TKey
), typeof (TResult
)),
759 Expression
.Constant (inner
),
760 Expression
.Quote (outerKeySelector
),
761 Expression
.Quote (innerKeySelector
),
762 Expression
.Quote (resultSelector
),
763 Expression
.Constant (comparer
)));
770 public static IQueryable
<TSource
> Intersect
<TSource
> (this IQueryable
<TSource
> source1
, IEnumerable
<TSource
> source2
)
772 Check
.Source1AndSource2 (source1
, source2
);
774 return source1
.Provider
.CreateQuery
<TSource
> (
776 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
778 Expression
.Constant (source2
)));
781 public static IQueryable
<TSource
> Intersect
<TSource
> (this IQueryable
<TSource
> source1
, IEnumerable
<TSource
> source2
, IEqualityComparer
<TSource
> comparer
)
783 Check
.Source1AndSource2 (source1
, source2
);
785 return source1
.Provider
.CreateQuery
<TSource
> (
787 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
789 Expression
.Constant (source2
),
790 Expression
.Constant (comparer
)));
797 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
)
799 Check
.JoinSelectors (outer
, inner
, outerKeySelector
, innerKeySelector
, resultSelector
);
801 return outer
.Provider
.CreateQuery
<TResult
> (
803 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TOuter
), typeof (TInner
), typeof (TKey
), typeof (TResult
)),
805 Expression
.Constant (inner
),
806 Expression
.Quote (outerKeySelector
),
807 Expression
.Quote (innerKeySelector
),
808 Expression
.Quote (resultSelector
)));
811 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
)
813 Check
.JoinSelectors (outer
, inner
, outerKeySelector
, innerKeySelector
, resultSelector
);
815 return outer
.Provider
.CreateQuery
<TResult
> (
817 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TOuter
), typeof (TInner
), typeof (TKey
), typeof (TResult
)),
819 Expression
.Constant (inner
),
820 Expression
.Quote (outerKeySelector
),
821 Expression
.Quote (innerKeySelector
),
822 Expression
.Quote (resultSelector
),
823 Expression
.Constant (comparer
)));
831 public static TSource Last
<TSource
> (this IQueryable
<TSource
> source
)
833 Check
.Source (source
);
835 return source
.Provider
.Execute
<TSource
> (
837 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
841 public static TSource Last
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, bool>> predicate
)
843 Check
.SourceAndPredicate (source
, predicate
);
845 return source
.Provider
.Execute
<TSource
> (
847 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
849 Expression
.Quote (predicate
)));
854 #region LastOrDefault
856 public static TSource LastOrDefault
<TSource
> (this IQueryable
<TSource
> source
)
858 Check
.Source (source
);
860 return source
.Provider
.Execute
<TSource
> (
862 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
866 public static TSource LastOrDefault
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, bool>> predicate
)
868 Check
.SourceAndPredicate (source
, predicate
);
870 return source
.Provider
.Execute
<TSource
> (
872 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
874 Expression
.Quote (predicate
)));
881 public static long LongCount
<TSource
> (this IQueryable
<TSource
> source
)
883 Check
.Source (source
);
885 return source
.Execute
<long, TSource
> (MethodBase
.GetCurrentMethod ());
888 public static long LongCount
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, bool>> predicate
)
890 Check
.SourceAndPredicate (source
, predicate
);
892 return source
.Provider
.Execute
<long> (
894 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
896 Expression
.Quote (predicate
)));
903 public static TSource Max
<TSource
> (this IQueryable
<TSource
> source
)
905 Check
.Source (source
);
907 return source
.Provider
.Execute
<TSource
> (
909 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
913 public static TResult Max
<TSource
, TResult
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, TResult
>> selector
)
915 Check
.Source (source
);
917 return source
.Provider
.Execute
<TResult
> (
919 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TResult
)),
921 Expression
.Quote (selector
)));
929 public static TSource Min
<TSource
> (this IQueryable
<TSource
> source
)
931 Check
.Source (source
);
933 return source
.Provider
.Execute
<TSource
> (
935 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
939 public static TResult Min
<TSource
, TResult
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, TResult
>> selector
)
941 Check
.SourceAndSelector (source
, selector
);
943 return source
.Provider
.Execute
<TResult
> (
945 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TResult
)),
947 Expression
.Quote (selector
)));
955 public static IQueryable
<TResult
> OfType
<TResult
> (this IQueryable source
)
957 Check
.Source (source
);
959 return (IQueryable
<TResult
>) source
.Provider
.CreateQuery (
961 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TResult
)),
969 public static IOrderedQueryable
<TSource
> OrderBy
<TSource
, TKey
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, TKey
>> keySelector
)
971 Check
.SourceAndKeySelector (source
, keySelector
);
973 return (IOrderedQueryable
<TSource
>) source
.Provider
.CreateQuery
<TSource
> (
975 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
)),
977 Expression
.Quote (keySelector
)));
980 public static IOrderedQueryable
<TSource
> OrderBy
<TSource
, TKey
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, TKey
>> keySelector
, IComparer
<TKey
> comparer
)
982 Check
.SourceAndKeySelector (source
, keySelector
);
984 return (IOrderedQueryable
<TSource
>) source
.Provider
.CreateQuery
<TSource
> (
986 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
)),
988 Expression
.Quote (keySelector
),
989 Expression
.Constant (comparer
)));
994 #region OrderByDescending
996 public static IOrderedQueryable
<TSource
> OrderByDescending
<TSource
, TKey
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, TKey
>> keySelector
)
998 Check
.SourceAndKeySelector (source
, keySelector
);
1000 return (IOrderedQueryable
<TSource
>) source
.Provider
.CreateQuery
<TSource
> (
1002 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
)),
1004 Expression
.Quote (keySelector
)));
1007 public static IOrderedQueryable
<TSource
> OrderByDescending
<TSource
, TKey
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, TKey
>> keySelector
, IComparer
<TKey
> comparer
)
1009 Check
.SourceAndKeySelector (source
, keySelector
);
1011 return (IOrderedQueryable
<TSource
>) source
.Provider
.CreateQuery
<TSource
> (
1013 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
)),
1015 Expression
.Quote (keySelector
),
1016 Expression
.Constant (comparer
)));
1023 public static IQueryable
<TSource
> Reverse
<TSource
> (this IQueryable
<TSource
> source
)
1025 Check
.Source (source
);
1027 return source
.Provider
.CreateQuery
<TSource
> (
1029 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1030 source
.Expression
));
1037 public static IQueryable
<TResult
> Select
<TSource
, TResult
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, TResult
>> selector
)
1039 Check
.SourceAndSelector (source
, selector
);
1041 return source
.Provider
.CreateQuery
<TResult
> (
1043 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TResult
)),
1045 Expression
.Quote (selector
)));
1048 public static IQueryable
<TResult
> Select
<TSource
, TResult
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, int, TResult
>> selector
)
1050 Check
.SourceAndSelector (source
, selector
);
1052 return source
.Provider
.CreateQuery
<TResult
> (
1054 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TResult
)),
1056 Expression
.Quote (selector
)));
1063 public static IQueryable
<TResult
> SelectMany
<TSource
, TResult
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, IEnumerable
<TResult
>>> selector
)
1065 Check
.SourceAndSelector (source
, selector
);
1067 return source
.Provider
.CreateQuery
<TResult
> (
1069 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TResult
)),
1071 Expression
.Quote (selector
)));
1074 public static IQueryable
<TResult
> SelectMany
<TSource
, TResult
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, int, IEnumerable
<TResult
>>> selector
)
1076 Check
.SourceAndSelector (source
, selector
);
1078 return source
.Provider
.CreateQuery
<TResult
> (
1080 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TResult
)),
1082 Expression
.Quote (selector
)));
1085 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
)
1087 Check
.SourceAndCollectionSelectorAndResultSelector (source
, collectionSelector
, resultSelector
);
1089 return source
.Provider
.CreateQuery
<TResult
> (
1091 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TCollection
), typeof (TResult
)),
1093 Expression
.Quote (collectionSelector
),
1094 Expression
.Quote (resultSelector
)));
1097 public static IQueryable
<TResult
> SelectMany
<TSource
, TCollection
, TResult
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, IEnumerable
<TCollection
>>> collectionSelector
, Expression
<Func
<TSource
, TCollection
, TResult
>> resultSelector
)
1099 Check
.SourceAndCollectionSelectorAndResultSelector (source
, collectionSelector
, resultSelector
);
1101 return source
.Provider
.CreateQuery
<TResult
> (
1103 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TCollection
), typeof (TResult
)),
1105 Expression
.Quote (collectionSelector
),
1106 Expression
.Quote (resultSelector
)));
1111 #region SequenceEqual
1113 public static bool SequenceEqual
<TSource
> (this IQueryable
<TSource
> source1
, IEnumerable
<TSource
> source2
)
1115 Check
.Source1AndSource2 (source1
, source2
);
1117 return source1
.Provider
.Execute
<bool> (
1119 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1121 Expression
.Constant (source2
)));
1124 public static bool SequenceEqual
<TSource
> (this IQueryable
<TSource
> source1
, IEnumerable
<TSource
> source2
, IEqualityComparer
<TSource
> comparer
)
1126 Check
.Source1AndSource2 (source1
, source2
);
1128 return source1
.Provider
.Execute
<bool> (
1130 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1132 Expression
.Constant (source2
),
1133 Expression
.Constant (comparer
)));
1140 public static TSource Single
<TSource
> (this IQueryable
<TSource
> source
)
1142 Check
.Source (source
);
1144 return source
.Provider
.Execute
<TSource
> (
1146 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1147 source
.Expression
));
1150 public static TSource Single
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, bool>> predicate
)
1152 Check
.SourceAndPredicate (source
, predicate
);
1154 return source
.Provider
.Execute
<TSource
> (
1156 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1158 Expression
.Quote (predicate
)));
1163 #region SingleOrDefault
1165 public static TSource SingleOrDefault
<TSource
> (this IQueryable
<TSource
> source
)
1167 Check
.Source (source
);
1169 return source
.Provider
.Execute
<TSource
> (
1171 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1172 source
.Expression
));
1175 public static TSource SingleOrDefault
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, bool>> predicate
)
1177 Check
.SourceAndPredicate (source
, predicate
);
1179 return source
.Provider
.Execute
<TSource
> (
1181 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1183 Expression
.Quote (predicate
)));
1190 public static IQueryable
<TSource
> Skip
<TSource
> (this IQueryable
<TSource
> source
, int count
)
1192 Check
.Source (source
);
1194 return source
.Provider
.CreateQuery
<TSource
> (
1196 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1198 Expression
.Constant (count
)));
1205 public static IQueryable
<TSource
> SkipWhile
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, bool>> predicate
)
1207 Check
.SourceAndPredicate (source
, predicate
);
1209 return source
.Provider
.CreateQuery
<TSource
> (
1211 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1213 Expression
.Quote (predicate
)));
1216 public static IQueryable
<TSource
> SkipWhile
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, int, bool>> predicate
)
1218 Check
.SourceAndPredicate (source
, predicate
);
1220 return source
.Provider
.CreateQuery
<TSource
> (
1222 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1224 Expression
.Quote (predicate
)));
1233 public static int Sum
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, int>> selector
)
1235 Check
.SourceAndSelector (source
, selector
);
1237 return source
.Provider
.Execute
<int> (
1239 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1241 Expression
.Quote (selector
)));
1244 public static int? Sum
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, int?>> selector
)
1246 Check
.SourceAndSelector (source
, selector
);
1248 return source
.Provider
.Execute
<int?> (
1250 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1252 Expression
.Quote (selector
)));
1255 public static long Sum
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, long>> selector
)
1257 Check
.SourceAndSelector (source
, selector
);
1259 return source
.Provider
.Execute
<long> (
1261 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1263 Expression
.Quote (selector
)));
1266 public static long? Sum
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, long?>> selector
)
1268 Check
.SourceAndSelector (source
, selector
);
1270 return source
.Provider
.Execute
<long?> (
1272 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1274 Expression
.Quote (selector
)));
1277 public static float Sum
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, float>> selector
)
1279 Check
.SourceAndSelector (source
, selector
);
1281 return source
.Provider
.Execute
<float> (
1283 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1285 Expression
.Quote (selector
)));
1288 public static float? Sum
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, float?>> selector
)
1290 Check
.SourceAndSelector (source
, selector
);
1292 return source
.Provider
.Execute
<float?> (
1294 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1296 Expression
.Quote (selector
)));
1299 public static double Sum
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, double>> selector
)
1301 Check
.SourceAndSelector (source
, selector
);
1303 return source
.Provider
.Execute
<double> (
1305 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1307 Expression
.Quote (selector
)));
1310 public static double? Sum
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, double?>> selector
)
1312 Check
.SourceAndSelector (source
, selector
);
1314 return source
.Provider
.Execute
<double?> (
1316 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1318 Expression
.Quote (selector
)));
1321 public static decimal Sum
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, decimal>> selector
)
1323 Check
.SourceAndSelector (source
, selector
);
1325 return source
.Provider
.Execute
<decimal> (
1327 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1329 Expression
.Quote (selector
)));
1332 public static decimal? Sum
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, decimal?>> selector
)
1334 Check
.SourceAndSelector (source
, selector
);
1336 return source
.Provider
.Execute
<decimal?> (
1338 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1340 Expression
.Quote (selector
)));
1343 public static int Sum (this IQueryable
<int> source
)
1345 Check
.Source (source
);
1347 return source
.Provider
.Execute
<int> (
1349 (MethodInfo
) MethodBase
.GetCurrentMethod (),
1350 source
.Expression
));
1353 public static int? Sum (this IQueryable
<int?> source
)
1355 Check
.Source (source
);
1357 return source
.Provider
.Execute
<int?> (
1359 (MethodInfo
) MethodBase
.GetCurrentMethod (),
1360 source
.Expression
));
1365 public static long Sum (this IQueryable
<long> source
)
1367 Check
.Source (source
);
1369 return source
.Provider
.Execute
<long> (
1371 (MethodInfo
) MethodBase
.GetCurrentMethod (),
1372 source
.Expression
));
1377 public static long? Sum (this IQueryable
<long?> source
)
1379 Check
.Source (source
);
1381 return source
.Provider
.Execute
<long?> (
1383 (MethodInfo
) MethodBase
.GetCurrentMethod (),
1384 source
.Expression
));
1387 public static float Sum (this IQueryable
<float> source
)
1389 Check
.Source (source
);
1391 return source
.Provider
.Execute
<float> (
1393 (MethodInfo
) MethodBase
.GetCurrentMethod (),
1394 source
.Expression
));
1397 public static float? Sum (this IQueryable
<float?> source
)
1399 Check
.Source (source
);
1401 return source
.Provider
.Execute
<float?> (
1403 (MethodInfo
) MethodBase
.GetCurrentMethod (),
1404 source
.Expression
));
1408 public static double Sum (this IQueryable
<double> source
)
1410 Check
.Source (source
);
1412 return source
.Provider
.Execute
<double> (
1414 (MethodInfo
) MethodBase
.GetCurrentMethod (),
1415 source
.Expression
));
1420 public static double? Sum (this IQueryable
<double?> source
)
1422 Check
.Source (source
);
1424 return source
.Provider
.Execute
<double?> (
1426 (MethodInfo
) MethodBase
.GetCurrentMethod (),
1427 source
.Expression
));
1431 public static decimal Sum (this IQueryable
<decimal> source
)
1433 Check
.Source (source
);
1435 return source
.Provider
.Execute
<decimal> (
1437 (MethodInfo
) MethodBase
.GetCurrentMethod (),
1438 source
.Expression
));
1443 public static decimal? Sum (this IQueryable
<decimal?> source
)
1445 Check
.Source (source
);
1447 return source
.Provider
.Execute
<decimal?> (
1449 (MethodInfo
) MethodBase
.GetCurrentMethod (),
1450 source
.Expression
));
1459 public static IQueryable
<TSource
> Take
<TSource
> (this IQueryable
<TSource
> source
, int count
)
1461 Check
.Source (source
);
1463 return source
.Provider
.CreateQuery
<TSource
> (
1465 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1467 Expression
.Constant (count
)));
1474 public static IQueryable
<TSource
> TakeWhile
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, bool>> predicate
)
1476 Check
.SourceAndPredicate (source
, predicate
);
1478 return source
.Provider
.CreateQuery
<TSource
> (
1480 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1482 Expression
.Quote (predicate
)));
1485 public static IQueryable
<TSource
> TakeWhile
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, int, bool>> predicate
)
1487 Check
.SourceAndPredicate (source
, predicate
);
1489 return source
.Provider
.CreateQuery
<TSource
> (
1491 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1493 Expression
.Quote (predicate
)));
1500 public static IOrderedQueryable
<TSource
> ThenBy
<TSource
, TKey
> (this IOrderedQueryable
<TSource
> source
, Expression
<Func
<TSource
, TKey
>> keySelector
)
1502 Check
.SourceAndKeySelector (source
, keySelector
);
1504 return (IOrderedQueryable
<TSource
>) source
.Provider
.CreateQuery (
1506 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
)),
1508 Expression
.Quote (keySelector
)));
1511 public static IOrderedQueryable
<TSource
> ThenBy
<TSource
, TKey
> (this IOrderedQueryable
<TSource
> source
, Expression
<Func
<TSource
, TKey
>> keySelector
, IComparer
<TKey
> comparer
)
1513 Check
.SourceAndKeySelector (source
, keySelector
);
1515 return (IOrderedQueryable
<TSource
>) source
.Provider
.CreateQuery (
1517 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
)),
1519 Expression
.Quote (keySelector
),
1520 Expression
.Constant (comparer
)));
1525 #region ThenByDescending
1527 public static IOrderedQueryable
<TSource
> ThenByDescending
<TSource
, TKey
> (this IOrderedQueryable
<TSource
> source
, Expression
<Func
<TSource
, TKey
>> keySelector
)
1529 Check
.SourceAndKeySelector (source
, keySelector
);
1531 return (IOrderedQueryable
<TSource
>) source
.Provider
.CreateQuery (
1533 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
)),
1535 Expression
.Quote (keySelector
)));
1538 public static IOrderedQueryable
<TSource
> ThenByDescending
<TSource
, TKey
> (this IOrderedQueryable
<TSource
> source
, Expression
<Func
<TSource
, TKey
>> keySelector
, IComparer
<TKey
> comparer
)
1540 Check
.SourceAndKeySelector (source
, keySelector
);
1542 return (IOrderedQueryable
<TSource
>) source
.Provider
.CreateQuery (
1544 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
), typeof (TKey
)),
1546 Expression
.Quote (keySelector
),
1547 Expression
.Constant (comparer
)));
1554 public static IQueryable
<TSource
> Union
<TSource
> (this IQueryable
<TSource
> source1
, IEnumerable
<TSource
> source2
)
1556 Check
.Source1AndSource2 (source1
, source2
);
1558 return source1
.Provider
.CreateQuery
<TSource
> (
1560 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1562 Expression
.Constant (source2
)));
1565 public static IQueryable
<TSource
> Union
<TSource
>(this IQueryable
<TSource
> source1
, IEnumerable
<TSource
> source2
, IEqualityComparer
<TSource
> comparer
)
1567 Check
.Source1AndSource2 (source1
, source2
);
1569 return source1
.Provider
.CreateQuery
<TSource
> (
1571 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1573 Expression
.Constant (source2
),
1574 Expression
.Constant (comparer
)));
1582 public static IQueryable
<TSource
> Where
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, bool>> predicate
)
1584 Check
.SourceAndPredicate (source
, predicate
);
1586 return source
.Provider
.CreateQuery
<TSource
> (
1588 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1590 Expression
.Quote (predicate
)));
1593 public static IQueryable
<TSource
> Where
<TSource
> (this IQueryable
<TSource
> source
, Expression
<Func
<TSource
, int, bool>> predicate
)
1595 Check
.SourceAndPredicate (source
, predicate
);
1597 return source
.Provider
.CreateQuery
<TSource
> (
1599 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TSource
)),
1601 Expression
.Quote (predicate
)));
1610 public static IQueryable
<TResult
> Zip
<TFirst
, TSecond
, TResult
> (this IQueryable
<TFirst
> source1
, IEnumerable
<TSecond
> source2
, Expression
<Func
<TFirst
, TSecond
, TResult
>> resultSelector
)
1612 Check
.Source1AndSource2 (source1
, source2
);
1613 if (resultSelector
== null)
1614 throw new ArgumentNullException ("resultSelector");
1616 return source1
.Provider
.CreateQuery
<TResult
> (
1618 MakeGeneric (MethodBase
.GetCurrentMethod (), typeof (TFirst
), typeof (TSecond
), typeof (TResult
)),
1620 Expression
.Quote (resultSelector
)));