예제 #1
0
 public static IQueryable <TSource> PagedBy <TSource>(this IQueryable <TSource> source, IPagedQueryInput input)
 {
     return(source.PagedBy(input.Page, input.PageSize));
 }
예제 #2
0
 /// <summary>
 /// 根据requestInput进行排序、分页后,转换为分页查询结果
 /// </summary>
 /// <typeparam name="TSource">原Entity类型</typeparam>
 /// <typeparam name="TDto">目标Dto类型</typeparam>
 /// <param name="query"></param>
 /// <param name="requestInput">查询参数</param>
 /// <returns></returns>
 public static PagedResultDto <TDto> ToPagedResult <TSource, TDto>(this IQueryable <TSource> query, IPagedQueryInput requestInput = null)
     where TSource : class
     where TDto : class
 {
     return(AsyncHelper.RunSync(() => query.ToPagedResultAsync <TSource, TDto>(requestInput)));
 }
예제 #3
0
        /// <summary>
        /// 根据requestInput进行排序、分页。
        /// </summary>
        public static IQueryable <T> ApplySortingAndPaging <T>(this IQueryable <T> query, IPagedQueryInput requestInput = null) where T : class
        {
            query = query.ApplySorting(requestInput);
            query = query.ApplyPaging(requestInput);

            return(query);
        }
예제 #4
0
        /// <summary>
        /// 根据requestInput进行排序、分页后,转换为分页查询结果
        /// </summary>
        /// <typeparam name="TSource">原Entity类型</typeparam>
        /// <typeparam name="TDto">目标Dto类型</typeparam>
        /// <param name="query"></param>
        /// <param name="requestInput">查询参数</param>
        /// <returns></returns>
        public static async Task <PagedResultDto <TDto> > ToPagedResultAsync <TSource, TDto>(this IQueryable <TSource> query, IPagedQueryInput requestInput = null)
            where TSource : class
            where TDto : class
        {
            var pagedQuery = query.ApplySortingAndPaging(requestInput);
            var result     = new PagedResultDto <TDto>()
            {
                Items = await pagedQuery.ProjectTo <TDto>().ToListAsync()
            };

            //没有分页参数,或者第1页的结果不足一整页时,不需要统计总记录数
            if (requestInput == null || (requestInput.SkipCount == 0 && result.Items.Count < requestInput.MaxResultCount))
            {
                result.TotalCount = result.Items.Count;
            }
            else
            {
                result.TotalCount = await query.CountAsync();
            }
            return(result);
        }