/// <summary> /// Sorts the elements of a sequence in ascending order according to a key. /// </summary> /// <typeparam name="TKey">The type of the key returned by the function that is represented by keySelector.</typeparam> /// <param name="keySelector">A function to extract a key from an element.</param> /// <returns>A new query instance containing all specified query parameters.</returns> public IOrderedQuery <T> OrderBy <TKey>(Expression <Func <T, TKey> > keySelector) { var expression = _expressionTranslator(keySelector); var sortExpression = new Expressions.SortExpression(expression, Expressions.SortDirection.Ascending); var query = new Query <T>(_dataProvider, _expressionTranslator, FilterExpressions, new[] { sortExpression }, SkipValue, TakeValue); return(query); }
/// <summary> /// Performs a subsequent ordering of the elements in a sequence in descending order, according to a key. /// </summary> /// <typeparam name="TKey">The type of the key returned by the function represented by keySelector.</typeparam> /// <param name="keySelector">A function to extract a key from each element.</param> /// <returns>A new query instance containing all specified query parameters.</returns> IOrderedQuery <T> IOrderedQuery <T> .ThenByDescending <TKey>(Expression <Func <T, TKey> > keySelector) { var sortExpressions = SortExpressions.AsEmptyIfNull().ToList(); if (!sortExpressions.Any()) { throw new InvalidOperationException("No sorting defined yet, use OrderBy or OrderByDescending first."); } var expression = _expressionTranslator(keySelector); var sortExpression = new Expressions.SortExpression(expression, Expressions.SortDirection.Descending); sortExpressions.Add(sortExpression); var query = new Query <T>(_dataProvider, _expressionTranslator, FilterExpressions, sortExpressions, SkipValue, TakeValue); return(query); }