public SqlProvider <T> FormatToPageList(int pageIndex, int pageSize) { var orderbySql = ResolveExpression.ResolveOrderBy(Context.QuerySet.OrderbyExpressionList); if (string.IsNullOrEmpty(orderbySql)) { throw new Exception("分页查询需要排序条件"); } var selectSql = ResolveExpression.ResolveSelect(typeof(T).GetProperties(), Context.QuerySet.SelectExpression, pageSize); var fromTableSql = FormatTableName(); var whereParams = ResolveExpression.ResolveWhere(Context.QuerySet.WhereExpression); var whereSql = whereParams.SqlCmd; Params = whereParams.Param; SqlString = $"SELECT COUNT(1) {fromTableSql} {whereSql};"; SqlString += $@"{selectSql} FROM ( SELECT * ,ROW_NUMBER() OVER ( {orderbySql} ) AS ROWNUMBER {fromTableSql} {whereSql} ) T WHERE ROWNUMBER > {(pageIndex - 1) * pageSize} AND ROWNUMBER <= {pageIndex * pageSize} {orderbySql};"; return(this); }
public SqlProvider <T> FormatToList() { var selectSql = ResolveExpression.ResolveSelect(typeof(T).GetProperties(), Context.QuerySet.SelectExpression, Context.QuerySet.TopNum); var fromTableSql = FormatTableName(); var whereParams = ResolveExpression.ResolveWhere(Context.QuerySet.WhereExpression); var whereSql = whereParams.SqlCmd; Params = whereParams.Param; var orderbySql = ResolveExpression.ResolveOrderBy(Context.QuerySet.OrderbyExpressionList); SqlString = $"{selectSql} {fromTableSql} {whereSql} {orderbySql}"; return(this); }