/* Copyright 2015-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
namespace MongoDB.Driver.Linq
{
///
/// Extension for .
///
public static class MongoQueryable
{
///
/// Determines whether a sequence contains any elements.
///
/// The type of the elements of .
/// A sequence to check for being empty.
/// The cancellation token.
///
/// true if the source sequence contains any elements; otherwise, false.
///
public static Task AnyAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, bool>(Queryable.Any, source),
source.Expression),
cancellationToken);
}
///
/// Determines whether any element of a sequence satisfies a condition.
///
/// The type of the elements of .
/// A sequence whose elements to test for a condition.
/// A function to test each element for a condition.
/// The cancellation token.
///
/// true if any elements in the source sequence pass the test in the specified predicate; otherwise, false.
///
public static Task AnyAsync(this IMongoQueryable source, Expression> predicate, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, bool>(Queryable.Any, source, predicate),
source.Expression,
Expression.Quote(predicate)),
cancellationToken);
}
///
/// Computes the average of a sequence of values.
///
/// A sequence of values to calculate the average of.
/// The cancellation token.
/// The average of the values in the sequence.
public static Task AverageAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, decimal>(Queryable.Average, source),
source.Expression),
cancellationToken);
}
///
/// Computes the average of a sequence of values.
///
/// A sequence of values to calculate the average of.
/// The cancellation token.
/// The average of the values in the sequence.
public static Task AverageAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, decimal?>(Queryable.Average, source),
source.Expression),
cancellationToken);
}
///
/// Computes the average of a sequence of values.
///
/// A sequence of values to calculate the average of.
/// The cancellation token.
/// The average of the values in the sequence.
public static Task AverageAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, double>(Queryable.Average, source),
source.Expression),
cancellationToken);
}
///
/// Computes the average of a sequence of values.
///
/// A sequence of values to calculate the average of.
/// The cancellation token.
/// The average of the values in the sequence.
public static Task AverageAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, double?>(Queryable.Average, source),
source.Expression),
cancellationToken);
}
///
/// Computes the average of a sequence of values.
///
/// A sequence of values to calculate the average of.
/// The cancellation token.
/// The average of the values in the sequence.
public static Task AverageAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, float>(Queryable.Average, source),
source.Expression),
cancellationToken);
}
///
/// Computes the average of a sequence of values.
///
/// A sequence of values to calculate the average of.
/// The cancellation token.
/// The average of the values in the sequence.
public static Task AverageAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, float?>(Queryable.Average, source),
source.Expression),
cancellationToken);
}
///
/// Computes the average of a sequence of values.
///
/// A sequence of values to calculate the average of.
/// The cancellation token.
/// The average of the values in the sequence.
public static Task AverageAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, double>(Queryable.Average, source),
source.Expression),
cancellationToken);
}
///
/// Computes the average of a sequence of values.
///
/// A sequence of values to calculate the average of.
/// The cancellation token.
/// The average of the values in the sequence.
public static Task AverageAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, double?>(Queryable.Average, source),
source.Expression),
cancellationToken);
}
///
/// Computes the average of a sequence of values.
///
/// A sequence of values to calculate the average of.
/// The cancellation token.
/// The average of the values in the sequence.
public static Task AverageAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, double>(Queryable.Average, source),
source.Expression),
cancellationToken);
}
///
/// Computes the average of a sequence of values.
///
/// A sequence of values to calculate the average of.
/// The cancellation token.
/// The average of the values in the sequence.
public static Task AverageAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, double?>(Queryable.Average, source),
source.Expression),
cancellationToken);
}
///
/// Computes the average of the sequence of values that is obtained
/// by invoking a projection function on each element of the input sequence.
///
/// The type of the elements of .
/// A sequence of values.
/// A projection function to apply to each element.
/// The cancellation token.
///
/// The average of the projected values.
///
public static Task AverageAsync(this IMongoQueryable source, Expression> selector, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, decimal>(Queryable.Average, source, selector),
source.Expression,
Expression.Quote(selector)),
cancellationToken);
}
///
/// Computes the average of the sequence of values that is obtained
/// by invoking a projection function on each element of the input sequence.
///
/// The type of the elements of .
/// A sequence of values.
/// A projection function to apply to each element.
/// The cancellation token.
///
/// The average of the projected values.
///
public static Task AverageAsync(this IMongoQueryable source, Expression> selector, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, decimal?>(Queryable.Average, source, selector),
source.Expression,
Expression.Quote(selector)),
cancellationToken);
}
///
/// Computes the average of the sequence of values that is obtained
/// by invoking a projection function on each element of the input sequence.
///
/// The type of the elements of .
/// A sequence of values.
/// A projection function to apply to each element.
/// The cancellation token.
///
/// The average of the projected values.
///
public static Task AverageAsync(this IMongoQueryable source, Expression> selector, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, double>(Queryable.Average, source, selector),
source.Expression,
Expression.Quote(selector)),
cancellationToken);
}
///
/// Computes the average of the sequence of values that is obtained
/// by invoking a projection function on each element of the input sequence.
///
/// The type of the elements of .
/// A sequence of values.
/// A projection function to apply to each element.
/// The cancellation token.
///
/// The average of the projected values.
///
public static Task AverageAsync(this IMongoQueryable source, Expression> selector, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, double?>(Queryable.Average, source, selector),
source.Expression,
Expression.Quote(selector)),
cancellationToken);
}
///
/// Computes the average of the sequence of values that is obtained
/// by invoking a projection function on each element of the input sequence.
///
/// The type of the elements of .
/// A sequence of values.
/// A projection function to apply to each element.
/// The cancellation token.
///
/// The average of the projected values.
///
public static Task AverageAsync(this IMongoQueryable source, Expression> selector, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, float>(Queryable.Average, source, selector),
source.Expression,
Expression.Quote(selector)),
cancellationToken);
}
///
/// Computes the average of the sequence of values that is obtained
/// by invoking a projection function on each element of the input sequence.
///
/// The type of the elements of .
/// A sequence of values.
/// A projection function to apply to each element.
/// The cancellation token.
///
/// The average of the projected values.
///
public static Task AverageAsync(this IMongoQueryable source, Expression> selector, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, float?>(Queryable.Average, source, selector),
source.Expression,
Expression.Quote(selector)),
cancellationToken);
}
///
/// Computes the average of the sequence of values that is obtained
/// by invoking a projection function on each element of the input sequence.
///
/// The type of the elements of .
/// A sequence of values.
/// A projection function to apply to each element.
/// The cancellation token.
///
/// The average of the projected values.
///
public static Task AverageAsync(this IMongoQueryable source, Expression> selector, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, double>(Queryable.Average, source, selector),
source.Expression,
Expression.Quote(selector)),
cancellationToken);
}
///
/// Computes the average of the sequence of values that is obtained
/// by invoking a projection function on each element of the input sequence.
///
/// The type of the elements of .
/// A sequence of values.
/// A projection function to apply to each element.
/// The cancellation token.
///
/// The average of the projected values.
///
public static Task AverageAsync(this IMongoQueryable source, Expression> selector, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, double?>(Queryable.Average, source, selector),
source.Expression,
Expression.Quote(selector)),
cancellationToken);
}
///
/// Computes the average of the sequence of values that is obtained
/// by invoking a projection function on each element of the input sequence.
///
/// The type of the elements of .
/// A sequence of values.
/// A projection function to apply to each element.
/// The cancellation token.
///
/// The average of the projected values.
///
public static Task AverageAsync(this IMongoQueryable source, Expression> selector, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, double>(Queryable.Average, source, selector),
source.Expression,
Expression.Quote(selector)),
cancellationToken);
}
///
/// Computes the average of the sequence of values that is obtained
/// by invoking a projection function on each element of the input sequence.
///
/// The type of the elements of .
/// A sequence of values.
/// A projection function to apply to each element.
/// The cancellation token.
///
/// The average of the projected values.
///
public static Task AverageAsync(this IMongoQueryable source, Expression> selector, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, double?>(Queryable.Average, source, selector),
source.Expression,
Expression.Quote(selector)),
cancellationToken);
}
///
/// Returns the number of elements in a sequence.
///
/// The type of the elements of .
/// The that contains the elements to be counted.
/// The cancellation token.
///
/// The number of elements in the input sequence.
///
public static Task CountAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, int>(Queryable.Count, source),
source.Expression),
cancellationToken);
}
///
/// Returns the number of elements in the specified sequence that satisfies a condition.
///
/// The type of the elements of .
/// An that contains the elements to be counted.
/// A function to test each element for a condition.
/// The cancellation token.
///
/// The number of elements in the sequence that satisfies the condition in the predicate function.
///
public static Task CountAsync(this IMongoQueryable source, Expression> predicate, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, int>(Queryable.Count, source, predicate),
source.Expression,
Expression.Quote(predicate)),
cancellationToken);
}
///
/// Returns distinct elements from a sequence by using the default equality comparer to compare values.
///
/// The type of the elements of .
/// The to remove duplicates from.
///
/// An that contains distinct elements from .
///
public static IMongoQueryable Distinct(this IMongoQueryable source)
{
return (IMongoQueryable)Queryable.Distinct(source);
}
///
/// Returns the first element of a sequence.
///
/// The type of the elements of .
/// The to return the first element of.
/// The cancellation token.
///
/// The first element in .
///
public static Task FirstAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, TSource>(Queryable.First, source),
source.Expression),
cancellationToken);
}
///
/// Returns the first element of a sequence that satisfies a specified condition.
///
/// The type of the elements of .
/// An to return an element from.
/// A function to test each element for a condition.
/// The cancellation token.
///
/// The first element in that passes the test in .
///
public static Task FirstAsync(this IMongoQueryable source, Expression> predicate, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, TSource>(Queryable.First, source, predicate),
source.Expression,
Expression.Quote(predicate)),
cancellationToken);
}
///
/// Returns the first element of a sequence, or a default value if the sequence contains no elements.
///
/// The type of the elements of .
/// The to return the first element of.
/// The cancellation token.
///
/// default() if is empty; otherwise, the first element in .
///
public static Task FirstOrDefaultAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, TSource>(Queryable.FirstOrDefault, source),
source.Expression),
cancellationToken);
}
///
/// Returns the first element of a sequence that satisfies a specified condition or a default value if no such element is found.
///
/// The type of the elements of .
/// An to return an element from.
/// A function to test each element for a condition.
/// The cancellation token.
///
/// default() if is empty or if no element passes the test specified by ; otherwise, the first element in that passes the test specified by .
///
public static Task FirstOrDefaultAsync(this IMongoQueryable source, Expression> predicate, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, TSource>(Queryable.FirstOrDefault, source, predicate),
source.Expression,
Expression.Quote(predicate)),
cancellationToken);
}
///
/// Groups the elements of a sequence according to a specified key selector function.
///
/// The type of the elements of .
/// The type of the key returned by the function represented in keySelector.
/// An whose elements to group.
/// A function to extract the key for each element.
///
/// An that has a type argument of
/// and where each object contains a sequence of objects
/// and a key.
///
public static IMongoQueryable> GroupBy(this IMongoQueryable source, Expression> keySelector)
{
return (IMongoQueryable>)Queryable.GroupBy(source, keySelector);
}
///
/// Groups the elements of a sequence according to a specified key selector function
/// and creates a result value from each group and its key.
///
/// The type of the elements of .
/// The type of the key returned by the function represented in keySelector.
/// The type of the result value returned by resultSelector.
/// An whose elements to group.
/// A function to extract the key for each element.
/// A function to create a result value from each group.
///
/// An that has a type argument of TResult and where
/// each element represents a projection over a group and its key.
///
public static IMongoQueryable GroupBy(this IMongoQueryable source, Expression> keySelector, Expression, TResult>> resultSelector)
{
return (IMongoQueryable)Queryable.GroupBy(source, keySelector, resultSelector);
}
///
/// Correlates the elements of two sequences based on key equality and groups the results.
///
/// The type of the elements of the first sequence.
/// The type of the elements of the second sequence.
/// The type of the keys returned by the key selector functions.
/// The type of the result elements.
/// The first sequence to join.
/// The sequence to join to the first sequence.
/// A function to extract the join key from each element of the first sequence.
/// A function to extract the join key from each element of the second sequence.
/// A function to create a result element from an element from the first sequence and a collection of matching elements from the second sequence.
///
/// An that contains elements of type obtained by performing a grouped join on two sequences.
///
public static IMongoQueryable GroupJoin(this IMongoQueryable outer, IEnumerable inner, Expression> outerKeySelector, Expression> innerKeySelector, Expression, TResult>> resultSelector)
{
return (IMongoQueryable)Queryable.GroupJoin(outer, inner, outerKeySelector, innerKeySelector, resultSelector);
}
///
/// Correlates the elements of two sequences based on key equality and groups the results.
///
/// The type of the elements of the first sequence.
/// The type of the elements of the second sequence.
/// The type of the keys returned by the key selector functions.
/// The type of the result elements.
/// The first sequence to join.
/// The collection to join to the first sequence.
/// A function to extract the join key from each element of the first sequence.
/// A function to extract the join key from each element of the second sequence.
/// A function to create a result element from an element from the first sequence and a collection of matching elements from the second sequence.
///
/// An that contains elements of type obtained by performing a grouped join on two sequences.
///
public static IMongoQueryable GroupJoin(this IMongoQueryable outer, IMongoCollection inner, Expression> outerKeySelector, Expression> innerKeySelector, Expression, TResult>> resultSelector)
{
return GroupJoin(outer, inner.AsQueryable(), outerKeySelector, innerKeySelector, resultSelector);
}
///
/// Correlates the elements of two sequences based on matching keys.
///
/// The type of the elements of the first sequence.
/// The type of the elements of the second sequence.
/// The type of the keys returned by the key selector functions.
/// The type of the result elements.
/// The first sequence to join.
/// The sequence to join to the first sequence.
/// A function to extract the join key from each element of the first sequence.
/// A function to extract the join key from each element of the second sequence.
/// A function to create a result element from two matching elements.
///
/// An that has elements of type obtained by performing an inner join on two sequences.
///
public static IMongoQueryable Join(this IMongoQueryable outer, IEnumerable inner, Expression> outerKeySelector, Expression> innerKeySelector, Expression> resultSelector)
{
return (IMongoQueryable)Queryable.Join(outer, inner.AsQueryable(), outerKeySelector, innerKeySelector, resultSelector);
}
///
/// Correlates the elements of two sequences based on matching keys.
///
/// The type of the elements of the first sequence.
/// The type of the elements of the second sequence.
/// The type of the keys returned by the key selector functions.
/// The type of the result elements.
/// The first sequence to join.
/// The sequence to join to the first sequence.
/// A function to extract the join key from each element of the first sequence.
/// A function to extract the join key from each element of the second sequence.
/// A function to create a result element from two matching elements.
///
/// An that has elements of type obtained by performing an inner join on two sequences.
///
public static IMongoQueryable Join(this IMongoQueryable outer, IMongoCollection inner, Expression> outerKeySelector, Expression> innerKeySelector, Expression> resultSelector)
{
return Join(outer, inner.AsQueryable(), outerKeySelector, innerKeySelector, resultSelector);
}
///
/// Returns the number of elements in a sequence.
///
/// The type of the elements of .
/// The that contains the elements to be counted.
/// The cancellation token.
///
/// The number of elements in the input sequence.
///
public static Task LongCountAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, long>(Queryable.LongCount, source),
source.Expression),
cancellationToken);
}
///
/// Returns the number of elements in the specified sequence that satisfies a condition.
///
/// The type of the elements of .
/// An that contains the elements to be counted.
/// A function to test each element for a condition.
/// The cancellation token.
///
/// The number of elements in the sequence that satisfies the condition in the predicate function.
///
public static Task LongCountAsync(this IMongoQueryable source, Expression> predicate, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, long>(Queryable.LongCount, source, predicate),
source.Expression,
Expression.Quote(predicate)),
cancellationToken);
}
///
/// Returns the maximum value in a generic .
///
/// The type of the elements of .
/// A sequence of values to determine the maximum of.
/// The cancellation token.
///
/// The maximum value in the sequence.
///
public static Task MaxAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, TSource>(Queryable.Max, source),
source.Expression),
cancellationToken);
}
///
/// Invokes a projection function on each element of a generic and returns the maximum resulting value.
///
/// The type of the elements of .
/// The type of the value returned by the function represented by .
/// A sequence of values to determine the maximum of.
/// A projection function to apply to each element.
/// The cancellation token.
///
/// The maximum value in the sequence.
///
public static Task MaxAsync(this IMongoQueryable source, Expression> selector, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, TResult>(Queryable.Max, source, selector),
source.Expression,
Expression.Quote(selector)),
cancellationToken);
}
///
/// Returns the minimum value in a generic .
///
/// The type of the elements of .
/// A sequence of values to determine the minimum of.
/// The cancellation token.
///
/// The minimum value in the sequence.
///
public static Task MinAsync(this IMongoQueryable source, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, TSource>(Queryable.Min, source),
source.Expression),
cancellationToken);
}
///
/// Invokes a projection function on each element of a generic and returns the minimum resulting value.
///
/// The type of the elements of .
/// The type of the value returned by the function represented by .
/// A sequence of values to determine the minimum of.
/// A projection function to apply to each element.
/// The cancellation token.
///
/// The minimum value in the sequence.
///
public static Task MinAsync(this IMongoQueryable source, Expression> selector, CancellationToken cancellationToken = default(CancellationToken))
{
return ((IMongoQueryProvider)source.Provider).ExecuteAsync(
Expression.Call(
GetMethodInfo, Expression>, TResult>(Queryable.Min, source, selector),
source.Expression,
Expression.Quote(selector)),
cancellationToken);
}
///
/// Filters the elements of an based on a specified type.
///
/// The type to filter the elements of the sequence on.
/// An whose elements to filter.
///
/// A collection that contains the elements from that have type .
///
public static IMongoQueryable OfType(this IMongoQueryable source)
{
return (IMongoQueryable)Queryable.OfType(source);
}
///
/// Sorts the elements of a sequence in ascending order according to a key.
///
/// The type of the elements of .
/// The type of the key returned by the function that is represented by keySelector.
/// A sequence of values to order.
/// A function to extract a key from an element.
///
/// An whose elements are sorted according to a key.
///
public static IOrderedMongoQueryable OrderBy(this IMongoQueryable source, Expression> keySelector)
{
return (IOrderedMongoQueryable)Queryable.OrderBy(source, keySelector);
}
///
/// Sorts the elements of a sequence in descending order according to a key.
///
/// The type of the elements of .
/// The type of the key returned by the function that is represented by keySelector.
/// A sequence of values to order.
/// A function to extract a key from an element.
///
/// An whose elements are sorted in descending order according to a key.
///
public static IOrderedMongoQueryable OrderByDescending(this IMongoQueryable source, Expression> keySelector)
{
return (IOrderedMongoQueryable)Queryable.OrderByDescending(source, keySelector);
}
///
/// Returns a sample of the elements in the