/// <summary> /// Creates an <see cref="IPaginated{T}" /> instance from the specified query. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query">The query.</param> /// <param name="paginatedCriteria">The paginated criteria.</param> /// <returns></returns> public static IPaginated <T> ToPaginated <T>(this IQueryable <T> query, IPaginatedCriteria paginatedCriteria) { return(new Paginated <T>( query.ToPage(paginatedCriteria.StartIndex, paginatedCriteria.PageSize, paginatedCriteria.SortDescriptions), query.Count(), paginatedCriteria.CurrentPage, paginatedCriteria.PageSize)); }
/// <summary> /// Gets the paginated data. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query">The query.</param> /// <param name="paginatedCriteria">The paginated criteria.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">query</exception> /// <exception cref="System.ArgumentNullException"></exception> public static IQueryable <T> ToPage <T>(this IQueryable <T> query, IPaginatedCriteria paginatedCriteria) { if (query == null) { throw new ArgumentNullException("query"); } return(query.ToPage(paginatedCriteria.StartIndex, paginatedCriteria.PageSize, paginatedCriteria.SortDescriptions)); }
/// <summary> /// Creates an <see cref="IPaginated{T}" /> instance from the specified query. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query">The query.</param> /// <param name="paginatedCriteria">The paginated criteria.</param> /// <returns></returns> public static async Task <IPaginated <T> > ToPaginatedAsync <T>(this IQueryable <T> query, IPaginatedCriteria paginatedCriteria) { return(new Paginated <T>( await query.ToPage(paginatedCriteria.StartIndex, paginatedCriteria.PageSize).ToListAsync(), await query.CountAsync(), paginatedCriteria.CurrentPage, paginatedCriteria.PageSize)); }
/// <summary> /// Creates an <see cref="IPaginated{T}" /> instance from the specified query. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query">The query.</param> /// <param name="paginatedCriteria">The paginated criteria.</param> /// <param name="cancellationToken"></param> /// <returns></returns> public static async Task <IPaginated <T> > ToPaginatedAsync <T>(this IQueryable <T> query, IPaginatedCriteria paginatedCriteria, CancellationToken cancellationToken = default) { var data = await query.ToPage(paginatedCriteria) .ToListAsync(cancellationToken); var count = await query.CountAsync(cancellationToken); // await Task.WhenAll(dataTask, countTask); // "A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext. For more information on how to avoid threading issues with DbContext, see https://go.microsoft.com/fwlink/?linkid=2097913. return(new Paginated <T>( data, count, paginatedCriteria.CurrentPage, paginatedCriteria.PageSize)); }
public static IQueryable <T> ToPage <T>(this IQueryable <T> query, IPaginatedCriteria criteria) { return(query.ToPage(criteria.StartIndex, criteria.PageSize)); }
/// <inheritdoc /> public async Task <IPaginated <TDto> > GetPaginated <TDto>(IPaginatedCriteria criteria, CancellationToken cancellationToken) => await Queryable .ProjectTo <TDto>(Mapper.ConfigurationProvider) .ToPaginatedAsync(criteria ?? new PaginatedCriteria(), cancellationToken);
/// <inheritdoc /> public virtual async Task <IPaginated <TEntity> > GetPaginated(IPaginatedCriteria criteria = null, CancellationToken cancellationToken = default) => await DbSet.ToPaginatedAsync(criteria ?? new PaginatedCriteria(), cancellationToken);