IQueryable.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Linq / IQueryable.cs / 1305376 / IQueryable.cs

                            using System; 
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection; 
using System.Text;
 
// Include Silverlight's managed resources 
#if SILVERLIGHT
using System.Core; 
#endif //SILVERLIGHT

namespace System.Linq {
 
    public interface IQueryable : IEnumerable {
        Expression Expression { get; } 
        Type ElementType { get; } 

        // the provider that created this query 
        IQueryProvider Provider { get; }
    }

#if SILVERLIGHT 
    public interface IQueryable : IEnumerable, IQueryable {
#else 
    public interface IQueryable : IEnumerable, IQueryable { 
#endif
    } 

    public interface IQueryProvider{
        IQueryable CreateQuery(Expression expression);
        IQueryable CreateQuery(Expression expression); 

        object Execute(Expression expression); 
 
        TResult Execute(Expression expression);
    } 

    public interface IOrderedQueryable : IQueryable {
    }
 
#if SILVERLIGHT
    public interface IOrderedQueryable : IQueryable, IOrderedQueryable { 
#else 
    public interface IOrderedQueryable : IQueryable, IOrderedQueryable {
#endif 
    }

    public static class Queryable {
 
        public static IQueryable AsQueryable(this IEnumerable source) {
            if (source == null) 
                throw Error.ArgumentNull("source"); 
            if (source is IQueryable)
                return (IQueryable)source; 
            return new EnumerableQuery(source);
        }

        public static IQueryable AsQueryable(this IEnumerable source) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (source is IQueryable) 
                return (IQueryable)source;
            Type enumType = TypeHelper.FindGenericType(typeof(IEnumerable<>), source.GetType()); 
            if (enumType == null)
                throw Error.ArgumentNotIEnumerableGeneric("source");
            return EnumerableQuery.Create(enumType.GetGenericArguments()[0], source);
        } 

        public static IQueryable Where(this IQueryable source, Expression> predicate) { 
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (predicate == null) 
                throw Error.ArgumentNull("predicate");
            return source.Provider.CreateQuery(
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(predicate) } 
                    )); 
        }
 
        public static IQueryable Where(this IQueryable source, Expression> predicate) {
            if (source == null)
                throw Error.ArgumentNull("source");
            if (predicate == null) 
                throw Error.ArgumentNull("predicate");
            return source.Provider.CreateQuery( 
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(predicate) }
                    ));
        }
 
        public static IQueryable OfType(this IQueryable source) {
            if (source == null) 
                throw Error.ArgumentNull("source"); 
            return source.Provider.CreateQuery(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
                    new Expression[] { source.Expression }
                    )); 
        }
 
        public static IQueryable Cast(this IQueryable source) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            return source.Provider.CreateQuery(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)), 
                    new Expression[] { source.Expression }
                    )); 
        } 

        public static IQueryable Select(this IQueryable source, Expression> selector) { 
            if (source == null)
                throw Error.ArgumentNull("source");
            if (selector == null)
                throw Error.ArgumentNull("selector"); 
            return source.Provider.CreateQuery(
                Expression.Call( 
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResult)),
                    new Expression[] { source.Expression, Expression.Quote(selector) } 
                    ));
        }

        public static IQueryable Select(this IQueryable source, Expression> selector) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (selector == null) 
                throw Error.ArgumentNull("selector");
            return source.Provider.CreateQuery( 
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResult)),
                    new Expression[] { source.Expression, Expression.Quote(selector) } 
                    ));
        } 
 
        public static IQueryable SelectMany(this IQueryable source, Expression>> selector) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (selector == null)
                throw Error.ArgumentNull("selector");
            return source.Provider.CreateQuery( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResult)), 
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    )); 
        }

        public static IQueryable SelectMany(this IQueryable source, Expression>> selector) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (selector == null) 
                throw Error.ArgumentNull("selector"); 
            return source.Provider.CreateQuery(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResult)),
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    )); 
        }
 
        public static IQueryable SelectMany(this IQueryable source, Expression>> collectionSelector, Expression> resultSelector){ 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (collectionSelector == null)
                throw Error.ArgumentNull("collectionSelector");
            if (resultSelector == null)
                throw Error.ArgumentNull("resultSelector"); 
            return source.Provider.CreateQuery(
                Expression.Call( 
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TCollection), typeof(TResult)),
                    new Expression[] { source.Expression, Expression.Quote(collectionSelector), Expression.Quote(resultSelector) } 
                    ));
        }

        public static IQueryable SelectMany(this IQueryable source, Expression>> collectionSelector, Expression> resultSelector) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (collectionSelector == null) 
                throw Error.ArgumentNull("collectionSelector");
            if (resultSelector == null) 
                throw Error.ArgumentNull("resultSelector");
            return source.Provider.CreateQuery(
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TCollection), typeof(TResult)),
                    new Expression[] { source.Expression, Expression.Quote(collectionSelector), Expression.Quote(resultSelector) } 
                    )); 
        }
 
        private static Expression GetSourceExpression(IEnumerable source) {
            IQueryable q = source as IQueryable;
            if (q != null) return q.Expression;
            return Expression.Constant(source, typeof(IEnumerable)); 
        }
 
        public static IQueryable Join(this IQueryable outer, IEnumerable inner, Expression> outerKeySelector, Expression> innerKeySelector, Expression> resultSelector) { 
            if (outer == null)
                throw Error.ArgumentNull("outer"); 
            if (inner == null)
                throw Error.ArgumentNull("inner");
            if (outerKeySelector == null)
                throw Error.ArgumentNull("outerKeySelector"); 
            if (innerKeySelector == null)
                throw Error.ArgumentNull("innerKeySelector"); 
            if (resultSelector == null) 
                throw Error.ArgumentNull("resultSelector");
            return outer.Provider.CreateQuery( 
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TOuter), typeof(TInner), typeof(TKey), typeof(TResult)),
                    new Expression[] { 
                        outer.Expression,
                        GetSourceExpression(inner), 
                        Expression.Quote(outerKeySelector), 
                        Expression.Quote(innerKeySelector),
                        Expression.Quote(resultSelector) 
                        }
                    ));
        }
 
        public static IQueryable Join(this IQueryable outer, IEnumerable inner, Expression> outerKeySelector, Expression> innerKeySelector, Expression> resultSelector, IEqualityComparer comparer) {
            if (outer == null) 
                throw Error.ArgumentNull("outer"); 
            if (inner == null)
                throw Error.ArgumentNull("inner"); 
            if (outerKeySelector == null)
                throw Error.ArgumentNull("outerKeySelector");
            if (innerKeySelector == null)
                throw Error.ArgumentNull("innerKeySelector"); 
            if (resultSelector == null)
                throw Error.ArgumentNull("resultSelector"); 
            return outer.Provider.CreateQuery( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TOuter), typeof(TInner), typeof(TKey), typeof(TResult)),
                    new Expression[] {
                        outer.Expression,
                        GetSourceExpression(inner), 
                        Expression.Quote(outerKeySelector),
                        Expression.Quote(innerKeySelector), 
                        Expression.Quote(resultSelector), 
                        Expression.Constant(comparer, typeof(IEqualityComparer))
                        } 
                    ));
        }

        public static IQueryable GroupJoin(this IQueryable outer, IEnumerable inner, Expression> outerKeySelector, Expression> innerKeySelector, Expression, TResult>> resultSelector) { 
            if (outer == null)
                throw Error.ArgumentNull("outer"); 
            if (inner == null) 
                throw Error.ArgumentNull("inner");
            if (outerKeySelector == null) 
                throw Error.ArgumentNull("outerKeySelector");
            if (innerKeySelector == null)
                throw Error.ArgumentNull("innerKeySelector");
            if (resultSelector == null) 
                throw Error.ArgumentNull("resultSelector");
            return outer.Provider.CreateQuery( 
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TOuter), typeof(TInner), typeof(TKey), typeof(TResult)), 
                    new Expression[] {
                        outer.Expression,
                        GetSourceExpression(inner),
                        Expression.Quote(outerKeySelector), 
                        Expression.Quote(innerKeySelector),
                        Expression.Quote(resultSelector) } 
                    )); 
        }
 
        public static IQueryable GroupJoin(this IQueryable outer, IEnumerable inner, Expression> outerKeySelector, Expression> innerKeySelector, Expression, TResult>> resultSelector, IEqualityComparer comparer) {
            if (outer == null)
                throw Error.ArgumentNull("outer");
            if (inner == null) 
                throw Error.ArgumentNull("inner");
            if (outerKeySelector == null) 
                throw Error.ArgumentNull("outerKeySelector"); 
            if (innerKeySelector == null)
                throw Error.ArgumentNull("innerKeySelector"); 
            if (resultSelector == null)
                throw Error.ArgumentNull("resultSelector");
            return outer.Provider.CreateQuery(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TOuter), typeof(TInner), typeof(TKey), typeof(TResult)), 
                    new Expression[] { 
                        outer.Expression,
                        GetSourceExpression(inner), 
                        Expression.Quote(outerKeySelector),
                        Expression.Quote(innerKeySelector),
                        Expression.Quote(resultSelector),
                        Expression.Constant(comparer, typeof(IEqualityComparer)) } 
                    ));
        } 
 
        public static IOrderedQueryable OrderBy(this IQueryable source, Expression> keySelector)
        { 
            if (source == null)
                throw Error.ArgumentNull("source");
            if (keySelector == null)
                throw Error.ArgumentNull("keySelector"); 
            return (IOrderedQueryable) source.Provider.CreateQuery(
                Expression.Call( 
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)),
                    new Expression[] { source.Expression, Expression.Quote(keySelector) } 
                    ));
        }

        public static IOrderedQueryable OrderBy(this IQueryable source, Expression> keySelector, IComparer comparer) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (keySelector == null) 
                throw Error.ArgumentNull("keySelector");
            return (IOrderedQueryable) source.Provider.CreateQuery( 
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)),
                    new Expression[] { source.Expression, Expression.Quote(keySelector), Expression.Constant(comparer, typeof(IComparer)) } 
                    ));
        } 
 
        public static IOrderedQueryable OrderByDescending(this IQueryable source, Expression> keySelector) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (keySelector == null)
                throw Error.ArgumentNull("keySelector");
            return (IOrderedQueryable) source.Provider.CreateQuery( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), 
                    new Expression[] { source.Expression, Expression.Quote(keySelector) }
                    )); 
        }

        public static IOrderedQueryable OrderByDescending(this IQueryable source, Expression> keySelector, IComparer comparer) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (keySelector == null) 
                throw Error.ArgumentNull("keySelector"); 
            return (IOrderedQueryable) source.Provider.CreateQuery(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)),
                    new Expression[] { source.Expression, Expression.Quote(keySelector), Expression.Constant(comparer, typeof(IComparer)) }
                    )); 
        }
 
        public static IOrderedQueryable ThenBy(this IOrderedQueryable source, Expression> keySelector) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (keySelector == null)
                throw Error.ArgumentNull("keySelector");
            return (IOrderedQueryable) source.Provider.CreateQuery(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), 
                    new Expression[] { source.Expression, Expression.Quote(keySelector) } 
                    ));
        } 

        public static IOrderedQueryable ThenBy(this IOrderedQueryable source, Expression> keySelector, IComparer comparer) {
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (keySelector == null)
                throw Error.ArgumentNull("keySelector"); 
            return (IOrderedQueryable) source.Provider.CreateQuery( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)),
                    new Expression[] { source.Expression, Expression.Quote(keySelector), Expression.Constant(comparer, typeof(IComparer)) }
                    ));
        } 

        public static IOrderedQueryable ThenByDescending(this IOrderedQueryable source, Expression> keySelector) { 
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (keySelector == null) 
                throw Error.ArgumentNull("keySelector");
            return (IOrderedQueryable) source.Provider.CreateQuery(
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)),
                    new Expression[] { source.Expression, Expression.Quote(keySelector) } 
                    )); 
        }
 
        public static IOrderedQueryable ThenByDescending(this IOrderedQueryable source, Expression> keySelector, IComparer comparer) {
            if (source == null)
                throw Error.ArgumentNull("source");
            if (keySelector == null) 
                throw Error.ArgumentNull("keySelector");
            return (IOrderedQueryable) source.Provider.CreateQuery( 
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), 
                    new Expression[] { source.Expression, Expression.Quote(keySelector), Expression.Constant(comparer, typeof(IComparer)) }
                    ));
        }
 
        public static IQueryable Take(this IQueryable source, int count) {
            if (source == null) 
                throw Error.ArgumentNull("source"); 
            return source.Provider.CreateQuery(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Constant(count) }
                    )); 
        }
 
        public static IQueryable TakeWhile(this IQueryable source, Expression> predicate) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (predicate == null)
                throw Error.ArgumentNull("predicate");
            return source.Provider.CreateQuery(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(predicate) } 
                    ));
        } 

        public static IQueryable TakeWhile(this IQueryable source, Expression> predicate) {
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (predicate == null)
                throw Error.ArgumentNull("predicate"); 
            return source.Provider.CreateQuery( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(predicate) }
                    ));
        } 

        public static IQueryable Skip(this IQueryable source, int count) { 
            if (source == null) 
                throw Error.ArgumentNull("source");
            return source.Provider.CreateQuery( 
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Constant(count) } 
                    ));
        } 
 
        public static IQueryable SkipWhile(this IQueryable source, Expression> predicate) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (predicate == null)
                throw Error.ArgumentNull("predicate");
            return source.Provider.CreateQuery( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(predicate) }
                    )); 
        }

        public static IQueryable SkipWhile(this IQueryable source, Expression> predicate) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (predicate == null) 
                throw Error.ArgumentNull("predicate"); 
            return source.Provider.CreateQuery(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(predicate) }
                    )); 
        }
 
        public static IQueryable> GroupBy(this IQueryable source, Expression> keySelector) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (keySelector == null)
                throw Error.ArgumentNull("keySelector");
            return source.Provider.CreateQuery>(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), 
                    new Expression[] { source.Expression, Expression.Quote(keySelector) } 
                    ));
        } 

        public static IQueryable> GroupBy(this IQueryable source, Expression> keySelector, Expression> elementSelector) {
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (keySelector == null)
                throw Error.ArgumentNull("keySelector"); 
            if (elementSelector == null) 
                throw Error.ArgumentNull("elementSelector");
            return source.Provider.CreateQuery>( 
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey), typeof(TElement)),
                    new Expression[] { source.Expression, Expression.Quote(keySelector), Expression.Quote(elementSelector) } 
                    ));
        } 
 
        public static IQueryable> GroupBy(this IQueryable source, Expression> keySelector, IEqualityComparer comparer) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (keySelector == null)
                throw Error.ArgumentNull("keySelector");
            return source.Provider.CreateQuery>( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey)), 
                    new Expression[] { source.Expression, Expression.Quote(keySelector), Expression.Constant(comparer, typeof(IEqualityComparer)) }
                    )); 
        }

        public static IQueryable> GroupBy(this IQueryable source, Expression> keySelector, Expression> elementSelector, IEqualityComparer comparer) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (keySelector == null) 
                throw Error.ArgumentNull("keySelector"); 
            if (elementSelector == null)
                throw Error.ArgumentNull("elementSelector"); 
            return source.Provider.CreateQuery>(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey), typeof(TElement)), 
                    new Expression[] { source.Expression, Expression.Quote(keySelector), Expression.Quote(elementSelector), Expression.Constant(comparer, typeof(IEqualityComparer)) }
                    )); 
        } 

        public static IQueryable GroupBy(this IQueryable source, Expression> keySelector, Expression> elementSelector, Expression, TResult>> resultSelector) 
        {
            if (source == null)
                throw Error.ArgumentNull("source");
            if (keySelector == null) 
                throw Error.ArgumentNull("keySelector");
            if (elementSelector == null) 
                throw Error.ArgumentNull("elementSelector"); 
            if (resultSelector == null)
                throw Error.ArgumentNull("resultSelector"); 
            return source.Provider.CreateQuery(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey), typeof(TElement), typeof(TResult)), 
                    new Expression[] { source.Expression, Expression.Quote(keySelector), Expression.Quote(elementSelector), Expression.Quote(resultSelector) }
                    )); 
        } 

        public static IQueryable GroupBy(this IQueryable source, Expression> keySelector,Expression, TResult>> resultSelector) 
        {
            if (source == null)
                throw Error.ArgumentNull("source");
            if (keySelector == null) 
                throw Error.ArgumentNull("keySelector");
            if (resultSelector == null) 
                throw Error.ArgumentNull("resultSelector"); 
            return source.Provider.CreateQuery(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey), typeof(TResult)),
                    new Expression[] { source.Expression, Expression.Quote(keySelector), Expression.Quote(resultSelector) }
                    )); 
        }
 
        public static IQueryable GroupBy(this IQueryable source, Expression> keySelector, Expression, TResult>> resultSelector, IEqualityComparer comparer) 
        {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (keySelector == null)
                throw Error.ArgumentNull("keySelector");
            if (resultSelector == null) 
                throw Error.ArgumentNull("resultSelector");
            return source.Provider.CreateQuery( 
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey), typeof(TResult)), 
                    new Expression[] { source.Expression, Expression.Quote(keySelector), Expression.Quote(resultSelector), Expression.Constant(comparer, typeof(IEqualityComparer)) }
                    ));
        }
 
        public static IQueryable GroupBy(this IQueryable source, Expression> keySelector, Expression> elementSelector, Expression, TResult>> resultSelector, IEqualityComparer comparer)
        { 
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (keySelector == null) 
                throw Error.ArgumentNull("keySelector");
            if (elementSelector == null)
                throw Error.ArgumentNull("elementSelector");
            if (resultSelector == null) 
                throw Error.ArgumentNull("resultSelector");
            return source.Provider.CreateQuery( 
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TKey), typeof(TElement), typeof(TResult)), 
                    new Expression[] { source.Expression, Expression.Quote(keySelector), Expression.Quote(elementSelector), Expression.Quote(resultSelector), Expression.Constant(comparer, typeof(IEqualityComparer)) }
                    ));
        }
 
        public static IQueryable Distinct(this IQueryable source) {
            if (source == null) 
                throw Error.ArgumentNull("source"); 
            return source.Provider.CreateQuery(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression }
                    )); 
        }
 
        public static IQueryable Distinct(this IQueryable source, IEqualityComparer comparer) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            return source.Provider.CreateQuery(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Constant(comparer, typeof(IEqualityComparer)) }
                    )); 
        } 

        public static IQueryable Concat(this IQueryable source1, IEnumerable source2) { 
            if (source1 == null)
                throw Error.ArgumentNull("source1");
            if (source2 == null)
                throw Error.ArgumentNull("source2"); 
            return source1.Provider.CreateQuery(
                Expression.Call( 
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source1.Expression, GetSourceExpression(source2) } 
                    ));
        }

        public static IQueryable Zip(this IQueryable source1, IEnumerable source2, Expression> resultSelector) { 
            if (source1 == null)
                throw Error.ArgumentNull("source1"); 
            if (source2 == null) 
                throw Error.ArgumentNull("source2");
            if (resultSelector == null) 
                throw Error.ArgumentNull("resultSelector");
            return source1.Provider.CreateQuery(
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TFirst), typeof(TSecond), typeof(TResult)),
                    new Expression[] { source1.Expression, GetSourceExpression(source2), Expression.Quote(resultSelector) } 
                    )); 
        }
 
        public static IQueryable Union(this IQueryable source1, IEnumerable source2) {
            if (source1 == null)
                throw Error.ArgumentNull("source1");
            if (source2 == null) 
                throw Error.ArgumentNull("source2");
            return source1.Provider.CreateQuery( 
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source1.Expression, GetSourceExpression(source2) }
                    ));
        }
 
        public static IQueryable Union(this IQueryable source1, IEnumerable source2, IEqualityComparer comparer) {
            if (source1 == null) 
                throw Error.ArgumentNull("source1"); 
            if (source2 == null)
                throw Error.ArgumentNull("source2"); 
            return source1.Provider.CreateQuery(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] {
                        source1.Expression, 
                        GetSourceExpression(source2), 
                        Expression.Constant(comparer, typeof(IEqualityComparer))
                        } 
                    ));
        }

        public static IQueryable Intersect(this IQueryable source1, IEnumerable source2) { 
            if (source1 == null)
                throw Error.ArgumentNull("source1"); 
            if (source2 == null) 
                throw Error.ArgumentNull("source2");
            return source1.Provider.CreateQuery( 
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source1.Expression, GetSourceExpression(source2) } 
                    ));
        } 
 
        public static IQueryable Intersect(this IQueryable source1, IEnumerable source2, IEqualityComparer comparer) {
            if (source1 == null) 
                throw Error.ArgumentNull("source1");
            if (source2 == null)
                throw Error.ArgumentNull("source2");
            return source1.Provider.CreateQuery( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] {
                        source1.Expression, 
                        GetSourceExpression(source2),
                        Expression.Constant(comparer, typeof(IEqualityComparer))
                        }
                    )); 
        }
 
        public static IQueryable Except(this IQueryable source1, IEnumerable source2) { 
            if (source1 == null)
                throw Error.ArgumentNull("source1"); 
            if (source2 == null)
                throw Error.ArgumentNull("source2");
            return source1.Provider.CreateQuery(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source1.Expression, GetSourceExpression(source2) } 
                    ));
        } 

        public static IQueryable Except(this IQueryable source1, IEnumerable source2, IEqualityComparer comparer) {
            if (source1 == null)
                throw Error.ArgumentNull("source1"); 
            if (source2 == null)
                throw Error.ArgumentNull("source2"); 
            return source1.Provider.CreateQuery( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] {
                        source1.Expression,
                        GetSourceExpression(source2), 
                        Expression.Constant(comparer, typeof(IEqualityComparer))
                        } 
                    )); 
        }
 
        public static TSource First(this IQueryable source) {
            if (source == null)
                throw Error.ArgumentNull("source");
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression }
                    )); 
        }

        public static TSource First(this IQueryable source, Expression> predicate) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (predicate == null) 
                throw Error.ArgumentNull("predicate"); 
            return source.Provider.Execute(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(predicate) }
                    )); 
        }
 
        public static TSource FirstOrDefault(this IQueryable source) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            return source.Provider.Execute(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression }
                    )); 
        } 

        public static TSource FirstOrDefault(this IQueryable source, Expression> predicate) { 
            if (source == null)
                throw Error.ArgumentNull("source");
            if (predicate == null)
                throw Error.ArgumentNull("predicate"); 
            return source.Provider.Execute(
                Expression.Call( 
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(predicate) } 
                    ));
        }

        public static TSource Last(this IQueryable source) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression }
                    ));
        } 

        public static TSource Last(this IQueryable source, Expression> predicate) { 
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (predicate == null) 
                throw Error.ArgumentNull("predicate");
            return source.Provider.Execute(
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(predicate) } 
                    )); 
        }
 
        public static TSource LastOrDefault(this IQueryable source) {
            if (source == null)
                throw Error.ArgumentNull("source");
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression }
                    )); 
        }

        public static TSource LastOrDefault(this IQueryable source, Expression> predicate) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (predicate == null) 
                throw Error.ArgumentNull("predicate"); 
            return source.Provider.Execute(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(predicate) }
                    )); 
        }
 
        public static TSource Single(this IQueryable source) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            return source.Provider.Execute(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression }
                    )); 
        } 

        public static TSource Single(this IQueryable source, Expression> predicate) { 
            if (source == null)
                throw Error.ArgumentNull("source");
            if (predicate == null)
                throw Error.ArgumentNull("predicate"); 
            return source.Provider.Execute(
                Expression.Call( 
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(predicate) } 
                    ));
        }

        public static TSource SingleOrDefault(this IQueryable source) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression }
                    ));
        } 

        public static TSource SingleOrDefault(this IQueryable source, Expression> predicate) { 
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (predicate == null) 
                throw Error.ArgumentNull("predicate");
            return source.Provider.Execute(
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(predicate) } 
                    )); 
        }
 
        public static TSource ElementAt(this IQueryable source, int index) {
            if (source == null)
                throw Error.ArgumentNull("source");
            if (index < 0) 
                throw Error.ArgumentOutOfRange("index");
            return source.Provider.Execute( 
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Constant(index) }
                    ));
        }
 
        public static TSource ElementAtOrDefault(this IQueryable source, int index) {
            if (source == null) 
                throw Error.ArgumentNull("source"); 
            return source.Provider.Execute(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Constant(index) }
                    )); 
        }
 
        public static IQueryable DefaultIfEmpty(this IQueryable source) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            return source.Provider.CreateQuery(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression }
                    )); 
        } 

        public static IQueryable DefaultIfEmpty(this IQueryable source, TSource defaultValue) { 
            if (source == null)
                throw Error.ArgumentNull("source");
            return source.Provider.CreateQuery(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Constant(defaultValue, typeof(TSource)) } 
                    ));
        } 

        public static bool Contains(this IQueryable source, TSource item) {
            if (source == null)
                throw Error.ArgumentNull("source"); 
            return source.Provider.Execute(
                Expression.Call( 
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Constant(item, typeof(TSource)) } 
                    ));
        }

        public static bool Contains(this IQueryable source, TSource item, IEqualityComparer comparer) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Constant(item, typeof(TSource)), Expression.Constant(comparer, typeof(IEqualityComparer)) }
                    ));
        } 

        public static IQueryable Reverse(this IQueryable source) { 
            if (source == null) 
                throw Error.ArgumentNull("source");
            return source.Provider.CreateQuery( 
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression } 
                    ));
        } 
 
        public static bool SequenceEqual(this IQueryable source1, IEnumerable source2) {
            if (source1 == null) 
                throw Error.ArgumentNull("source1");
            if (source2 == null)
                throw Error.ArgumentNull("source2");
            return source1.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source1.Expression, GetSourceExpression(source2) }
                    )); 
        }

        public static bool SequenceEqual(this IQueryable source1, IEnumerable source2, IEqualityComparer comparer) {
            if (source1 == null) 
                throw Error.ArgumentNull("source1");
            if (source2 == null) 
                throw Error.ArgumentNull("source2"); 
            return source1.Provider.Execute(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] {
                        source1.Expression, 
                        GetSourceExpression(source2),
                        Expression.Constant(comparer, typeof(IEqualityComparer)) 
                        } 
                    ));
        } 

        public static bool Any(this IQueryable source) {
            if (source == null)
                throw Error.ArgumentNull("source"); 
            return source.Provider.Execute(
                Expression.Call( 
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression } 
                    ));
        }

        public static bool Any(this IQueryable source, Expression> predicate) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (predicate == null) 
                throw Error.ArgumentNull("predicate");
            return source.Provider.Execute( 
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(predicate) } 
                    ));
        } 
 
        public static bool All(this IQueryable source, Expression> predicate) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (predicate == null)
                throw Error.ArgumentNull("predicate");
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(predicate) }
                    )); 
        }

        public static int Count(this IQueryable source) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            return source.Provider.Execute( 
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression }
                    ));
        }
 
        public static int Count(this IQueryable source, Expression> predicate) {
            if (source == null) 
                throw Error.ArgumentNull("source"); 
            if (predicate == null)
                throw Error.ArgumentNull("predicate"); 
            return source.Provider.Execute(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(predicate) }
                    )); 
        } 

        public static long LongCount(this IQueryable source) { 
            if (source == null)
                throw Error.ArgumentNull("source");
            return source.Provider.Execute(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression } 
                    ));
        } 

        public static long LongCount(this IQueryable source, Expression> predicate) {
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (predicate == null)
                throw Error.ArgumentNull("predicate"); 
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(predicate) }
                    ));
        } 

        public static TSource Min(this IQueryable source) { 
            if (source == null) 
                throw Error.ArgumentNull("source");
            return source.Provider.Execute( 
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression } 
                    ));
        } 
 
        public static TResult Min(this IQueryable source, Expression> selector) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (selector == null)
                throw Error.ArgumentNull("selector");
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResult)), 
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    )); 
        }

        public static TSource Max(this IQueryable source) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            return source.Provider.Execute( 
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression }
                    ));
        }
 
        public static TResult Max(this IQueryable source, Expression> selector) {
            if (source == null) 
                throw Error.ArgumentNull("source"); 
            if (selector == null)
                throw Error.ArgumentNull("selector"); 
            return source.Provider.Execute(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResult)), 
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    )); 
        } 

        public static int Sum(this IQueryable source) { 
            if (source == null)
                throw Error.ArgumentNull("source");
            return source.Provider.Execute(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()), 
                    new Expression[] { source.Expression } 
                    ));
        } 

        public static int? Sum(this IQueryable source) {
            if (source == null)
                throw Error.ArgumentNull("source"); 
            return source.Provider.Execute(
                Expression.Call( 
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()),
                    new Expression[] { source.Expression } 
                    ));
        }

        public static long Sum(this IQueryable source) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()),
                    new Expression[] { source.Expression }
                    ));
        } 

        public static long? Sum(this IQueryable source) { 
            if (source == null) 
                throw Error.ArgumentNull("source");
            return source.Provider.Execute( 
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()),
                    new Expression[] { source.Expression } 
                    ));
        } 
 
        public static float Sum(this IQueryable source) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            return source.Provider.Execute(
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()),
                    new Expression[] { source.Expression } 
                    )); 
        }
 
        public static float? Sum(this IQueryable source) {
            if (source == null)
                throw Error.ArgumentNull("source");
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()), 
                    new Expression[] { source.Expression }
                    )); 
        }

        public static double Sum(this IQueryable source) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            return source.Provider.Execute( 
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()), 
                    new Expression[] { source.Expression }
                    ));
        }
 
        public static double? Sum(this IQueryable source) {
            if (source == null) 
                throw Error.ArgumentNull("source"); 
            return source.Provider.Execute(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()),
                    new Expression[] { source.Expression }
                    )); 
        }
 
        public static decimal Sum(this IQueryable source) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            return source.Provider.Execute(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()), 
                    new Expression[] { source.Expression }
                    )); 
        } 

        public static decimal? Sum(this IQueryable source) { 
            if (source == null)
                throw Error.ArgumentNull("source");
            return source.Provider.Execute(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()), 
                    new Expression[] { source.Expression } 
                    ));
        } 

        public static int Sum(this IQueryable source, Expression> selector) {
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (selector == null)
                throw Error.ArgumentNull("selector"); 
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    ));
        } 

        public static int? Sum(this IQueryable source, Expression> selector) { 
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (selector == null) 
                throw Error.ArgumentNull("selector");
            return source.Provider.Execute(
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(selector) } 
                    )); 
        }
 
        public static long Sum(this IQueryable source, Expression> selector) {
            if (source == null)
                throw Error.ArgumentNull("source");
            if (selector == null) 
                throw Error.ArgumentNull("selector");
            return source.Provider.Execute( 
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    ));
        }
 
        public static long? Sum(this IQueryable source, Expression> selector) {
            if (source == null) 
                throw Error.ArgumentNull("source"); 
            if (selector == null)
                throw Error.ArgumentNull("selector"); 
            return source.Provider.Execute(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    )); 
        } 

        public static float Sum(this IQueryable source, Expression> selector) { 
            if (source == null)
                throw Error.ArgumentNull("source");
            if (selector == null)
                throw Error.ArgumentNull("selector"); 
            return source.Provider.Execute(
                Expression.Call( 
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(selector) } 
                    ));
        }

        public static float? Sum(this IQueryable source, Expression> selector) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (selector == null) 
                throw Error.ArgumentNull("selector");
            return source.Provider.Execute( 
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(selector) } 
                    ));
        } 
 
        public static double Sum(this IQueryable source, Expression> selector) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (selector == null)
                throw Error.ArgumentNull("selector");
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    )); 
        }

        public static double? Sum(this IQueryable source, Expression> selector) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (selector == null) 
                throw Error.ArgumentNull("selector"); 
            return source.Provider.Execute(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    )); 
        }
 
        public static decimal Sum(this IQueryable source, Expression> selector) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (selector == null)
                throw Error.ArgumentNull("selector");
            return source.Provider.Execute(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(selector) } 
                    ));
        } 

        public static decimal? Sum(this IQueryable source, Expression> selector) {
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (selector == null)
                throw Error.ArgumentNull("selector"); 
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    ));
        } 

        public static double Average(this IQueryable source) { 
            if (source == null) 
                throw Error.ArgumentNull("source");
            return source.Provider.Execute( 
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()),
                    new Expression[] { source.Expression } 
                    ));
        } 
 
        public static double? Average(this IQueryable source) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            return source.Provider.Execute(
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()),
                    new Expression[] { source.Expression } 
                    )); 
        }
 
        public static double Average(this IQueryable source) {
            if (source == null)
                throw Error.ArgumentNull("source");
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()), 
                    new Expression[] { source.Expression }
                    )); 
        }

        public static double? Average(this IQueryable source) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            return source.Provider.Execute( 
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()), 
                    new Expression[] { source.Expression }
                    ));
        }
 
        public static float Average(this IQueryable source)
        { 
            if (source == null) 
                throw Error.ArgumentNull("source");
            return source.Provider.Execute( 
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()),
                    new Expression[] { source.Expression } 
                    ));
        } 
 
        public static float? Average(this IQueryable source)
        { 
            if (source == null)
                throw Error.ArgumentNull("source");
            return source.Provider.Execute(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()), 
                    new Expression[] { source.Expression } 
                    ));
        } 

        public static double Average(this IQueryable source) {
            if (source == null)
                throw Error.ArgumentNull("source"); 
            return source.Provider.Execute(
                Expression.Call( 
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()),
                    new Expression[] { source.Expression } 
                    ));
        }

        public static double? Average(this IQueryable source) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()),
                    new Expression[] { source.Expression }
                    ));
        } 

        public static decimal Average(this IQueryable source) { 
            if (source == null) 
                throw Error.ArgumentNull("source");
            return source.Provider.Execute( 
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()),
                    new Expression[] { source.Expression } 
                    ));
        } 
 
        public static decimal? Average(this IQueryable source) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            return source.Provider.Execute(
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()),
                    new Expression[] { source.Expression } 
                    )); 
        }
 
        public static double Average(this IQueryable source, Expression> selector) {
            if (source == null)
                throw Error.ArgumentNull("source");
            if (selector == null) 
                throw Error.ArgumentNull("selector");
            return source.Provider.Execute( 
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    ));
        }
 
        public static double? Average(this IQueryable source, Expression> selector) {
            if (source == null) 
                throw Error.ArgumentNull("source"); 
            if (selector == null)
                throw Error.ArgumentNull("selector"); 
            return source.Provider.Execute(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    )); 
        } 

        public static float Average(this IQueryable source, Expression> selector) 
        {
            if (source == null)
                throw Error.ArgumentNull("source");
            if (selector == null) 
                throw Error.ArgumentNull("selector");
            return source.Provider.Execute( 
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    ));
        }
 
        public static float? Average(this IQueryable source, Expression> selector)
        { 
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (selector == null) 
                throw Error.ArgumentNull("selector");
            return source.Provider.Execute(
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(selector) } 
                    )); 
        }
 
        public static double Average(this IQueryable source, Expression> selector) {
            if (source == null)
                throw Error.ArgumentNull("source");
            if (selector == null) 
                throw Error.ArgumentNull("selector");
            return source.Provider.Execute( 
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    ));
        }
 
        public static double? Average(this IQueryable source, Expression> selector) {
            if (source == null) 
                throw Error.ArgumentNull("source"); 
            if (selector == null)
                throw Error.ArgumentNull("selector"); 
            return source.Provider.Execute(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    )); 
        } 

        public static double Average(this IQueryable source, Expression> selector) { 
            if (source == null)
                throw Error.ArgumentNull("source");
            if (selector == null)
                throw Error.ArgumentNull("selector"); 
            return source.Provider.Execute(
                Expression.Call( 
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(selector) } 
                    ));
        }

        public static double? Average(this IQueryable source, Expression> selector) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (selector == null) 
                throw Error.ArgumentNull("selector");
            return source.Provider.Execute( 
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(selector) } 
                    ));
        } 
 
        public static decimal Average(this IQueryable source, Expression> selector) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (selector == null)
                throw Error.ArgumentNull("selector");
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    )); 
        }

        public static decimal? Average(this IQueryable source, Expression> selector) {
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (selector == null) 
                throw Error.ArgumentNull("selector"); 
            return source.Provider.Execute(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
                    new Expression[] { source.Expression, Expression.Quote(selector) }
                    )); 
        }
 
        public static TSource Aggregate(this IQueryable source, Expression> func) { 
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (func == null)
                throw Error.ArgumentNull("func");
            return source.Provider.Execute(
                Expression.Call( 
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)), 
                    new Expression[] { source.Expression, Expression.Quote(func) } 
                    ));
        } 

        public static TAccumulate Aggregate(this IQueryable source, TAccumulate seed, Expression> func) {
            if (source == null)
                throw Error.ArgumentNull("source"); 
            if (func == null)
                throw Error.ArgumentNull("func"); 
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TAccumulate)),
                    new Expression[] { source.Expression, Expression.Constant(seed), Expression.Quote(func) }
                    ));
        } 

        public static TResult Aggregate(this IQueryable source, TAccumulate seed, Expression> func, Expression> selector) { 
            if (source == null) 
                throw Error.ArgumentNull("source");
            if (func == null) 
                throw Error.ArgumentNull("func");
            if (selector == null)
                throw Error.ArgumentNull("selector");
            return source.Provider.Execute( 
                Expression.Call(
                    null, 
                    ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TAccumulate), typeof(TResult)), 
                    new Expression[] { source.Expression, Expression.Constant(seed), Expression.Quote(func), Expression.Quote(selector) }
                    )); 
        }
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK