/// <summary>
 /// 通过查询条件获取全部数据
 /// </summary>
 /// <param name="pg">查询条件,需要自己在Service层构造</param>
 /// <param name="orderList">排序方式,默认id倒序</param>
 /// <returns>查询结果数组</returns>
 public virtual List <T> Find(PredicateGroup pg, List <OrderItem> orderList = null)
 {
     using (var conn = ConnectionFactory.CreateConnection())
     {
         return(conn.GetList <T>(pg, SortExtension.ToSortList <T>(orderList)).ToList());
     }
 }
        public PageResult <T> GetPager(PredicateGroup pg, PageQuery pageQuery)
        {
            var result = new PageResult <T>();

            ////PageIndex等于0时返回全部
            if (pageQuery.PageIndex == 0)
            {
                using (var conn = ConnectionFactory.CreateConnection())
                {
                    result.Row   = conn.GetList <T>(pg, SortExtension.ToSortList <T>(pageQuery.OrderList)).ToList();
                    result.Total = result.Row.Count;
                    return(result);
                }
            }

            if (pageQuery.PageIndex < 0)
            {
                throw new ArgumentException(nameof(pageQuery.PageIndex));
            }

            if (pageQuery.PageSize <= 0)
            {
                throw new ArgumentException(nameof(pageQuery.PageSize));
            }

            using (var conn = ConnectionFactory.CreateConnection())
            {
                var total = conn.Count <T>(pg);
                result.Total = total;

                //判断请求有数据时再查询
                if (total > (pageQuery.PageIndex - 1) * pageQuery.PageSize)
                {
                    result.Row = conn.GetPage <T>(pg, SortExtension.ToSortList <T>(pageQuery.OrderList), pageQuery.PageIndex - 1, pageQuery.PageSize)
                                 .ToList();
                }

                return(result);
            }
        }