Exemple #1
0
        /// <summary>
        /// Pages the source according to Paging details provided
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">Source IQueriable for which Paging should be added</param>
        /// <param name="paging">Paging contract. Must have RecordsPerPage and Page.</param>
        /// <returns><see cref="IQueryable<typeparamref name="T"/>"/></returns>
        public static IQueryable <T> DoPaging <T>(this IQueryable <T> source, Paging paging)
        {
            if (paging == null)
            {
                return(source);
            }

            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            PagingHelper.CalculatePagingDetails(paging, source.Count(), out int skipElements, out int takeElements);

            return(source is IOrderedQueryable?
                   source.Skip(skipElements).Take(takeElements) :
                       source.OrderBy(p => 0).Skip(skipElements).Take(takeElements));
        }