public static PagedResult <T> PagedQuery <T>(this IDbConnection db, int pageSize, int pageNumber, Expression <Func <T, bool> > whereExpression = null, Expression <Func <T, object> > groupByexpression = null, params Expression <Func <T, object> >[] orderbyExpressions) where T : class { var sqllam = new SqlLam <T>(db.GetAdapter()); var countSqlam = new SqlLam <T>(db.GetAdapter()); if (whereExpression != null) { sqllam = sqllam.Where(whereExpression); countSqlam = countSqlam.Where(whereExpression); } if (orderbyExpressions != null && orderbyExpressions.Length > 0) { sqllam = sqllam.OrderBy(orderbyExpressions); } if (groupByexpression != null) { sqllam = sqllam.GroupBy(groupByexpression); } countSqlam = countSqlam.Count(); var countRet = db.Query <int>(countSqlam.SqlString, countSqlam.Parameters).FirstOrDefault(); //var sqlString = sqllam.SqlString; //var param = sqllam.Parameters; //string parameterString = GetParameterString(sqllam.Parameters); var sqlstring = sqllam.QueryPage(pageSize, pageNumber); var retlist = db.Query <T>(sqlstring, sqllam.Parameters); return(new PagedResult <T>(retlist, countRet, pageSize, pageNumber)); }