@@ -13,6 +13,7 @@ public class DapperGriddlyResult<T> : GriddlyResult<T>
1313 Func < IDbConnection > _getConnection ;
1414 Func < IDbTransaction > _getTransaction ;
1515 string _sql ;
16+ string _outerSqlTemplate ;
1617 object _param ;
1718 Func < IDbConnection , IDbTransaction , string , object , IEnumerable < T > > _map ;
1819 Action < IDbConnection , IDbTransaction , IList < T > > _massage ;
@@ -21,12 +22,13 @@ public class DapperGriddlyResult<T> : GriddlyResult<T>
2122 bool _fixedSort ;
2223 static readonly bool _hasOverallCount = typeof ( IHasOverallCount ) . IsAssignableFrom ( typeof ( T ) ) ;
2324
24- public DapperGriddlyResult ( Func < IDbConnection > getConnection , string sql , object param , Func < IDbConnection , IDbTransaction , string , object , IEnumerable < T > > map = null , Action < IDbConnection , IDbTransaction , IList < T > > massage = null , bool fixedSort = false , Func < IDbTransaction > getTransaction = null )
25+ public DapperGriddlyResult ( Func < IDbConnection > getConnection , string sql , object param , Func < IDbConnection , IDbTransaction , string , object , IEnumerable < T > > map = null , Action < IDbConnection , IDbTransaction , IList < T > > massage = null , bool fixedSort = false , Func < IDbTransaction > getTransaction = null , string outerSqlTemplate = "{0}" )
2526 : base ( null )
2627 {
2728 _getConnection = getConnection ;
2829 _sql = sql ;
2930 _param = param ;
31+ _outerSqlTemplate = outerSqlTemplate ;
3032
3133 if ( map == null )
3234 _map = DefaultMap ;
@@ -59,7 +61,8 @@ public override void PopulateSummaryValues(GriddlySettings<T> settings)
5961 aggregateExpression . AppendFormat ( "{0}({1}) AS _a{2}" , col . SummaryFunction , col . ExpressionString , i ) ;
6062 }
6163
62- string sql = string . Format ( "{0} FROM ({1}) [_proj]" , aggregateExpression . ToString ( ) , _sql ) ;
64+ string sql = string . Format ( _outerSqlTemplate ,
65+ string . Format ( "{0} FROM ({1}) [_proj]" , aggregateExpression . ToString ( ) , _sql ) ) ;
6366
6467 try
6568 {
@@ -82,7 +85,8 @@ public override long GetCount()
8285 {
8386 if ( _overallCount == null )
8487 {
85- string sql = string . Format ( "SELECT CAST(COUNT(*) as bigint) FROM ({0}) [_proj]" , _sql ) ;
88+ string sql = string . Format ( _outerSqlTemplate ,
89+ string . Format ( "SELECT CAST(COUNT(*) as bigint) FROM ({0}) [_proj]" , _sql ) ) ;
8690
8791 try
8892 {
@@ -118,14 +122,16 @@ SELECT COUNT(0) AS OverallCount FROM _data
118122)
119123SELECT * FROM _data CROSS APPLY _count " + ( _fixedSort ? "" : "ORDER BY {1}" ) + " OFFSET {2} ROWS FETCH NEXT {3} ROWS ONLY" ;
120124
121- string sql = string . Format ( format , _sql , BuildSortClause ( sortFields ) , pageNumber * pageSize , pageSize ) ;
125+ string sql = string . Format ( _outerSqlTemplate ,
126+ string . Format ( format , _sql , BuildSortClause ( sortFields ) , pageNumber * pageSize , pageSize ) ) ;
122127
123128 return ExecuteQuery ( sql , _param ) ;
124129 }
125130
126131 public override IEnumerable < T > GetAll ( SortField [ ] sortFields )
127132 {
128- string sql = _fixedSort ? _sql : string . Format ( "{0} ORDER BY {1}" , _sql , BuildSortClause ( sortFields ) ) ;
133+ string sql = string . Format ( _outerSqlTemplate ,
134+ _fixedSort ? _sql : string . Format ( "{0} ORDER BY {1}" , _sql , BuildSortClause ( sortFields ) ) ) ;
129135
130136 return ExecuteQuery ( sql , _param ) ;
131137 }
0 commit comments