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); 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} {whereSql};"; SqlString += $"{selectSql} {fromTableSql} {nolockSql} {whereSql} {orderbySql} LIMIT {(pageIndex - 1) * pageSize},{pageSize}"; return(this); }
public override SqlProvider FormatCount() { var selectSql = "SELECT COUNT(*)"; 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 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 FormatExists() { var selectSql = "SELECT 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} LIMIT 1"; return(this); }
public override SqlProvider FormatGet <T>() { var selectSql = ResolveExpression.ResolveSelect(typeof(T).GetProperties(), SetContext.SelectExpression); 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} {whereSql} {nolockSql} {orderbySql} LIMIT 1"; return(this); }
public override SqlProvider FormatToList <T>() { var selectSql = ResolveExpression.ResolveSelect(typeof(T).GetProperties(), SelectExpression); var fromTableSql = FormatTableName(); var nolockSql = ResolveExpression.ResolveWithNoLock(NoLock); var whereParams = ResolveExpression.ResolveWhere(WhereExpression); var whereSql = whereParams.SqlCmd; Params = whereParams.Param; var orderbySql = ResolveExpression.ResolveOrderBy(OrderbyExpressionList); var topNum = TopNum; var limitSql = topNum.HasValue ? " LIMIT " + topNum.Value : ""; SqlString = $"{selectSql} {fromTableSql} {nolockSql} {whereSql} {orderbySql} {limitSql}"; return(this); }