public PagingDataSource <T> GetPagingDataSource <T>(string withSql, OrderPagingQuery <T> query,
                                                            string tableName = "TResult") where T : class
        {
            string    pageSql   = SqlBuildHelper.BuildPageSql(withSql, query, tableName);
            string    countSql  = SqlBuildHelper.BuildCountSql(withSql, tableName);
            IList <T> pagedList = Database.SqlQuery <T>(pageSql).ToList();
            int       count     = Database.SqlQuery <int>(countSql).FirstOrDefault();
            var       result    = new PagingDataSource <T>(pagedList, query, count);

            return(result);
        }
        public async Task <PagingQueryResult <OrderPagingQueryDTO> > Handle(OrderPagingQuery request, CancellationToken cancellationToken)
        {
            var result = new PagingQueryResult <OrderPagingQueryDTO>();

            request.CheckPagingParam();

            var specification = new OrderPagingSpecification(identityService.GetOrganizationId(), request.Page, request.PageSize, request.OrderBy, request.Desc, request.Search);

            result.Total = await orderRepository.Get(specification).CountAsync();

            result.Data = await orderRepository.Paging(specification).Select(x => OrderPagingQueryDTO.From(x)).ToListAsync();

            return(result);
        }
        public async Task <IActionResult> Get([FromQuery] OrderPagingQuery query)
        {
            var list = await _mediator.Send(query);

            return(Ok(list));
        }
        public static PagingDataSource <T> ToPagingDataSource <T>(this IQueryable <T> queryableSource, OrderPagingQuery <T> orderPagingQuery, int recordCount = 0) where T : class
        {
            if (recordCount == 0 && orderPagingQuery.IsGetRecordCount)
            {
                recordCount = queryableSource.Count();
            }

            bool ordered = false;

            foreach (OrderField <T> orderfield in orderPagingQuery.OrderFieldStore.OrderFields)
            {
                string orderType = string.Empty;
                if (orderfield.OrderType == OrderType.Descending)
                {
                    orderType = ordered ? "ThenByDescending" : "OrderByDescending";
                }
                else
                {
                    orderType = ordered ? "ThenBy" : "OrderBy";
                }

                if (!string.IsNullOrEmpty(orderType))
                {
                    Expression sortExpression = UnBox(orderfield.FieldExpression.Body);
                    Type       sortType       = sortExpression.Type;
                    Type       funType        = typeof(Func <,>);

                    funType = funType.MakeGenericType(typeof(T), sortType);

                    LambdaExpression lambda = Expression.Lambda(funType, sortExpression, orderfield.FieldExpression.Parameters);

                    MethodCallExpression method = Expression.Call(typeof(Queryable), orderType,
                                                                  new Type[] { typeof(T), sortExpression.Type }, queryableSource.Expression, lambda);

                    queryableSource = queryableSource.Provider.CreateQuery <T>(method);
                    ordered         = true;
                }
            }
            return(ToPagingDataSource(queryableSource.Skip(orderPagingQuery.GetSkipCount()).Take(orderPagingQuery.PageSize).ToList(),
                                      orderPagingQuery, recordCount));
        }