Exemple #1
0
        //public static ObjectQuery<T> Include<T>(this ObjectQuery<T> objectQuery, IEnumerable<string> includes)
        //{
        //    if (includes != null && includes.Any())
        //    {
        //        foreach (var include in includes)
        //        {
        //            objectQuery = objectQuery.Include(include);
        //        }
        //    }
        //    return objectQuery;
        //}

        //public static ObjectQuery<T> OrderBy<T>(this ObjectQuery<T> objectQuery, IEnumerable<SortDescriptor> sortDesciptors)
        //{
        //    if (sortDesciptors != null && sortDesciptors.Any())
        //    {
        //        foreach (var sort in sortDesciptors)
        //        {
        //            objectQuery = objectQuery.OrderBy(sort.SortDirection == ListSortDirection.Ascending
        //                    ? string.Format("{0}.{1}", objectQuery.Name, sort.Member)
        //                    : string.Format("{0}.{1} desc", objectQuery.Name, sort.Member));
        //        }

        //    }
        //    return objectQuery;
        //}

        public static IQueryable <T> OrderBy <T>(this IQueryable <T> query, IEnumerable <SortDescriptor> sortDesciptors)
        {
            if (sortDesciptors != null && sortDesciptors.Any())
            {
                var sortBuilder = new SortDescriptorCollectionExpressionBuilder(query, sortDesciptors);
                query = sortBuilder.Sort() as IQueryable <T>;
            }
            return(query);
        }
Exemple #2
0
        /// <summary>
        /// Sorts the elements of a sequence using the specified sort descriptors.
        /// </summary>
        /// <param name="source">A sequence of values to sort.</param>
        /// <param name="sortDescriptors">The sort descriptors used for sorting.</param>
        /// <returns>
        /// An <see cref="IQueryable" /> whose elements are sorted according to a <paramref name="sortDescriptors"/>.
        /// </returns>
        public static IQueryable Sort(this IQueryable source, IEnumerable <SortDescriptor> sortDescriptors)
        {
            var builder = new SortDescriptorCollectionExpressionBuilder(source, sortDescriptors);

            return(builder.Sort());
        }