示例#1
0
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <typeparam name="T">实体</typeparam>
        /// <param name="util">查询参数</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页条数</param>
        /// <param name="table">要查询的表</param>
        /// <param name="cols">要查询的列</param>
        /// <returns></returns>
        public PageList <T> Query <T>(MySearchUtil util, int pageIndex, int pageSize, string table = "", string cols = "*")
        {
            if (string.IsNullOrWhiteSpace(table))
            {
                table = GetTableName(typeof(T));
            }

            string where = util.GetConditionClaus();
            string            orderby = util.GetOrderByClaus();
            DynamicParameters param   = util.GetPageListParameters();

            string sql = GetPagingQuerySql(cols, table, where, orderby, pageIndex, pageSize);

            using (var conn = GetConnection())
            {
                var list  = conn.Query <T>(sql, param);
                var total = param.Get <int>("RecordCount");
                return(new PageList <T>
                {
                    Body = list,
                    PageIndex = pageIndex,
                    PageSize = pageSize,
                    RecordCount = total
                });
            }
        }
示例#2
0
        /// <summary>
        /// 获取分页动态数据列表
        /// </summary>
        /// <param name="util">查询参数</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页条数</param>
        /// <param name="table">要查询的表</param>
        /// <param name="cols">要查询的列</param>
        /// <returns></returns>
        public PageList <dynamic> Query(MySearchUtil util, int pageIndex, int pageSize, string table, string cols = "*")
        {
            string where = util.GetConditionClaus();
            string            orderby = util.GetOrderByClaus();
            DynamicParameters param   = util.GetPageListParameters();

            string sql = GetPagingQuerySql(cols, table, where, orderby, pageIndex, pageSize);

            using (var conn = GetConnection())
            {
                var list  = conn.Query(sql, param);
                var total = param.Get <int>("RecordCount");
                return(new PageList <dynamic>
                {
                    Body = list,
                    PageIndex = pageIndex,
                    PageSize = pageSize,
                    RecordCount = total
                });
            }
        }