Ejemplo n.º 1
0
        /// <summary>
        /// Converts query results to an <see cref="ListResult{T}"/> object.
        /// </summary>
        /// <typeparam name="TSource">The type of items.</typeparam>
        /// <param name="source">The query to convert.</param>
        /// <param name="pageIndex">The index of the page of results to return. Use 1 to indicate the first page.</param>
        /// <param name="pageSize">The size of the page of results to return. <paramref name="pageIndex" /> is non-zero-based.</param>
        /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
        /// <returns>
        /// The task object representing the asynchronous operation.
        /// </returns>
        public static async Task <ListResult <TSource> > ToListResultAsync <TSource>(this IQueryable <TSource> source, int pageIndex, int pageSize, CancellationToken cancellationToken)
        {
            int total = await source.CountAsync(cancellationToken);

            if (total == 0)
            {
                return(ListResult <TSource> .Empty);
            }
            return(ListResult.Create(await source.Paging(pageIndex, pageSize).ToArrayAsync(cancellationToken), total));
        }
        /// <summary>
        /// Gets a collection of items, in a page of data, and materializes the result-set to a read-only collection.
        /// </summary>
        /// <typeparam name="T">The type of the query.</typeparam>
        /// <param name="context">The context.</param>
        /// <param name="query">The query.</param>
        /// <param name="pageIndex">Index of the page.</param>
        /// <param name="pageSize">The size of the page of results to return. <paramref name="offset" /> is non-zero-based.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// A collection of the <see cref="T" /> objects.
        /// </returns>
        public static async Task <ListResult <T> > FindItemsAsync <T>(this PartnerDbContext context, IQueryable <T> query, int pageIndex, int pageSize, CancellationToken cancellationToken)
        {
            int count = await query.CountAsync(cancellationToken);

            if (count == 0)
            {
                return(ListResult <T> .Empty);
            }
            return(ListResult.Create(await query.Paging(pageIndex, pageSize).ToListAsync(cancellationToken), count));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Converts query results to an <see cref="ListResult{T}"/> object.
 /// </summary>
 /// <typeparam name="TSource">The type of items.</typeparam>
 /// <param name="source">The query to convert.</param>
 /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
 /// <returns>
 /// The task object representing the asynchronous operation.
 /// </returns>
 public static async Task <ListResult <TSource> > ToListResultAsync <TSource>(this IQueryable <TSource> source, CancellationToken cancellationToken)
 {
     return(ListResult.Create(await source.ToArrayAsync(cancellationToken)));
 }