public ResponseResult<List<ProductOrderEntity>> QueryPaged(ProductOrderQuery query) { var result = ResponseResult<List<ProductOrderEntity>>.Default(); var conn = SessionFactory.CreateConnection(); try { var count = 0; var list = ProductOrderService.GetPaged(query, out count); result = ResponseResult<List<ProductOrderEntity>>.Success(list); result.TotalRowsCount = count; result.TotalPages = (count + query.PageSize - 1) / query.PageSize; } catch (System.Exception ex) { result = ResponseResult<List<ProductOrderEntity>>.Error( string.Format("获取{0}分页数据失败,错误{1}", "ProductOrder", ex.Message) ); } return result; }
/// <summary> /// 获取分页数据 /// </summary> /// <param name="query">查询条件</param> /// <param name="count">记录数</param> /// <returns></returns> public List<ProductOrderEntity> GetPaged(ProductOrderQuery query, out int count) { List<ProductOrderEntity> list = null; var conn = SessionFactory.CreateConnection(); try { var sortList = new List<DapperExtensions.ISort>(); sortList.Add(new DapperExtensions.Sort { PropertyName = "ID", Ascending = false }); IFieldPredicate predicate = null; if (!string.IsNullOrEmpty(query.OrderCode)) predicate = Predicates.Field<ProductOrderEntity>(f => f.OrderCode, Operator.Eq, query.OrderCode); count = DBHelper.Count<ProductOrderEntity>(conn, predicate); list = DBHelper.GetPaged<ProductOrderEntity>(conn, query.PageIndex, query.PageSize, predicate, sortList, false).ToList(); return list; } catch (System.Exception) { throw; } finally { conn.Close(); } }