예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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)
        {
            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);

            var sortExpressions = SortExpressions.ToList();

            sortExpressions.Add(sortExpression);

            var query = new Query <T>(_dataProvider, _expressionTranslator, FilterExpressions, sortExpressions, SkipValue, TakeValue);

            return(query);
        }
        public static IOrderedDataServiceQueryable <TEntity, TBase> OrderBy <TEntity, TBase>(this IDataServiceQueryable <TEntity, TBase> queriable, RLinq.SortExpression expression) where TEntity : TBase where TBase : Entity
        {
            var newQueriable = new OrderedDataServiceQueryable <TEntity, TBase>((DataServiceQueryable <TEntity, TBase>)queriable);

            newQueriable.Sortings.Clear();
            newQueriable.Sortings.Add(new DataServiceQueryable <TEntity, TBase> .Sort(expression));
            return(newQueriable);
        }