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 FormatExists() { var selectSql = "SELECT TOP 1 1"; var fromTableSql = FormatTableName(); var nolockSql = ResolveExpression.ResolveWithNoLock(SetContext.NoLock); var whereParams = ResolveExpression.ResolveWhere(SetContext.WhereExpression); var whereSql = whereParams.SqlCmd; Params = whereParams.Param; SqlString = $"{selectSql} {fromTableSql} {nolockSql} {whereSql}"; return(this); }
public override SqlProvider FormatSum <T>(LambdaExpression lambdaExpression) { var selectSql = ResolveExpression.ResolveSum(typeof(T).GetProperties(), lambdaExpression); var fromTableSql = FormatTableName(); var whereParams = ResolveExpression.ResolveWhere(SetContext.WhereExpression); var nolockSql = ResolveExpression.ResolveWithNoLock(SetContext.NoLock); var whereSql = whereParams.SqlCmd; Params = whereParams.Param; SqlString = $"{selectSql} {fromTableSql} {nolockSql} {whereSql} "; return(this); }
public override SqlProvider FormatCount() { var selectSql = "SELECT COUNT(1)"; var fromTableSql = FormatTableName(); var nolockSql = ResolveExpression.ResolveWithNoLock(NoLock); var whereParams = ResolveExpression.ResolveWhere(WhereExpression); var whereSql = whereParams.SqlCmd; Params = whereParams.Param; SqlString = $"{selectSql} {fromTableSql} {nolockSql} {whereSql} "; return(this); }
public override SqlProvider FormatGet <T>() { var selectSql = ResolveExpression.ResolveSelect(typeof(T).GetProperties(), SetContext.SelectExpression, 1); 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); }