/// <summary>
        /// Converts a query to an instance of PagedQueryResult, executing the query twice,
        /// once to get the total count and again to get the results.
        /// </summary>
        public static async Task <PagedQueryResult <T> > ToPagedResultAsync <T>(this IQueryable <T> source, IPageableQuery query)
        {
            Condition.Requires(source).IsNotNull();

            var result = new PagedQueryResult <T>();

            result.TotalItems = await source.CountAsync();

            result.Items = await source.Page(query).ToArrayAsync();

            PagingExtensions.MapPagingData <T>(query, result);

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Converts a query to an instance of PagedQueryResult, executing the query twice,
        /// once to get the total count and again to get the results.
        /// </summary>
        public static async Task <PagedQueryResult <T> > ToPagedResultAsync <T>(this IQueryable <T> source, IPageableQuery query)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var result = new PagedQueryResult <T>();

            result.TotalItems = await source.CountAsync();

            result.Items = await source.Page(query).ToArrayAsync();

            PagingExtensions.MapPagingData <T>(query, result);

            return(result);
        }