/// <summary> /// 从集合中查询指定数据筛选的分页信息 /// </summary> /// <typeparam name="TEntity">动态实体类型</typeparam> /// <typeparam name="TResult">要返回动态实体类型</typeparam> /// <param name="source">数据源</param> /// <param name="predicate">查询条件表达式</param> /// <param name="pageParameters">分页参数</param> /// <param name="selector">数据筛选表达式</param> /// <returns></returns> public static async Task <PageResult <TEntity> > ToPageAsync <TEntity>(this IQueryable <TEntity> source, PageParameters pageParameters) { pageParameters.NotNull(nameof(pageParameters)); var result = await source.WhereAsync(pageParameters.PageIndex, pageParameters.PageSize, null, pageParameters.OrderConditions); var list = await result.data.ToArrayAsync(); var total = result.totalNumber; return(new PageResult <TEntity>(list, total)); }
/// <summary> /// 从集合中查询指定输出DTO的分页信息 /// </summary> /// <typeparam name="TEntity">动态实体类型</typeparam> /// <typeparam name="TOutputDto">输出DTO数据类型</typeparam> /// <param name="source">数据源</param> /// <param name="predicate">查询条件表达式</param> /// <param name="pageParameters">分页参数</param> /// <returns></returns> public static async Task <PageResult <TOutputDto> > ToPageAsync <TEntity, TOutputDto>(this IQueryable <TEntity> source, Expression <Func <TEntity, bool> > predicate, PageParameters pageParameters) where TOutputDto : IOutputDto { pageParameters.NotNull(nameof(pageParameters)); var result = await source.WhereAsync(pageParameters.PageIndex, pageParameters.PageSize, predicate, pageParameters.OrderConditions); var list = await result.data.ToOutput <TOutputDto>().ToArrayAsync(); var total = result.totalNumber; return(new PageResult <TOutputDto>(list, total)); }
/// <summary> /// 从集合中查询指定数据筛选的分页信息 /// </summary> /// <typeparam name="TEntity">动态实体类型</typeparam> /// <typeparam name="TResult">要返回动态实体类型</typeparam> /// <param name="source">数据源</param> /// <param name="predicate">查询条件表达式</param> /// <param name="pageParameters">分页参数</param> /// <param name="selector">数据筛选表达式</param> /// <returns></returns> public static async Task <IPageResult <TResult> > ToPageAsync <TEntity, TResult>(this IQueryable <TEntity> source, Expression <Func <TEntity, bool> > predicate, PageParameters pageParameters, Expression <Func <TEntity, TResult> > selector) { pageParameters.NotNull(nameof(pageParameters)); selector.NotNull(nameof(selector)); var result = await source.WhereAsync(pageParameters.PageIndex, pageParameters.PageRow, predicate, pageParameters.OrderConditions); var list = await result.data.Select(selector).ToArrayAsync(); var total = result.totalNumber; return(new PageResult <TResult>(list, total)); }