示例#1
0
        /// <summary>
        ///  获取分页数据
        /// </summary>
        /// <param name="connectionString">数据信息</param>
        /// <param name="builder"></param>
        /// <param name="template"></param>
        /// <param name="orderColumn">排序列</param>
        /// <param name="orderBy">排序类型</param>
        /// <param name="offset">开始位置</param>
        /// <param name="pageRows">每页显示记录数</param>
        /// <param name="totalRows">总记录数</param>
        /// <returns>the list of query result.</returns>
        protected virtual IEnumerable <TResult> GetPaggingList <TResult>(string connectionString, SqlSelectBuilder builder, SqlSelectBuilder.SelectTemplate template, string orderColumn, ListResultsOrder orderBy, int?offset, int?pageRows, out int totalRows)
            where TResult : class
        {
            if (string.IsNullOrEmpty(orderColumn))
            {
                orderColumn = "1";
            }
            builder.OrderBy(orderBy == ListResultsOrder.Descending ? orderColumn + " DESC" : orderColumn + " ASC");
            builder.Limit(offset, pageRows);
            var resolveResult          = template.ResolveRawSql(0);
            IEnumerable <TResult> list = null;

            using (var conn = OpenDbConnection(connectionString))
            {
                string sql = resolveResult.Item1 + ";\n" + resolveResult.Item2;
                using (var multiple = conn.QueryMultiple(sql, template.Parameters))
                {
                    list      = multiple.Read <TResult>();
                    totalRows = multiple.ReadFirst <int>();
                }
            }
            return(list);
        }