public override SqlProvider FormatToPageList <T>(int pageIndex, int pageSize) { var orderbySql = ResolveExpression.ResolveOrderBy(SetContext.OrderbyExpressionList); if (string.IsNullOrEmpty(orderbySql)) { throw new DapperExtensionException("order by takes precedence over pagelist"); } var selectSql = ResolveExpression.ResolveSelect(typeof(T).GetProperties(), SetContext.SelectExpression, pageSize); var fromTableSql = FormatTableName(); var nolockSql = ResolveExpression.ResolveWithNoLock(SetContext.NoLock); var whereParams = ResolveExpression.ResolveWhere(SetContext.WhereExpression); var whereSql = whereParams.SqlCmd; Params = whereParams.Param; SqlString = $"SELECT COUNT(1) {fromTableSql} {nolockSql} {whereSql};"; SqlString += $@"{selectSql} FROM ( SELECT * ,ROW_NUMBER() OVER ( {orderbySql} ) AS ROWNUMBER {fromTableSql} {nolockSql} {whereSql} ) T WHERE ROWNUMBER > {(pageIndex - 1) * pageSize} AND ROWNUMBER <= {pageIndex * pageSize} {orderbySql};"; return(this); }
public override SqlProvider FormatGet <T>() { var selectSql = ResolveExpression.ResolveSelect(typeof(T).GetProperties(), Context.Set.SelectExpression, 1); var fromTableSql = FormatTableName(); var whereParams = ResolveExpression.ResolveWhere(Context.Set.WhereExpression); var whereSql = whereParams.SqlCmd; Params = whereParams.Param; var orderbySql = ResolveExpression.ResolveOrderBy(Context.Set.OrderbyExpressionList); SqlString = $"{selectSql} {fromTableSql} {whereSql} {orderbySql}"; return(this); }
public override SqlProvider FormatToList <T>() { var topNum = SetContext.TopNum; var selectSql = ResolveExpression.ResolveSelect(typeof(T).GetProperties(), SetContext.SelectExpression, topNum); var fromTableSql = FormatTableName(); var nolockSql = ResolveExpression.ResolveWithNoLock(SetContext.NoLock); var whereParams = ResolveExpression.ResolveWhere(SetContext.WhereExpression); var whereSql = whereParams.SqlCmd; Params = whereParams.Param; var orderbySql = ResolveExpression.ResolveOrderBy(SetContext.OrderbyExpressionList); SqlString = $"{selectSql} {fromTableSql} {nolockSql} {whereSql} {orderbySql}"; return(this); }