@@ -13,6 +13,7 @@ public class DapperGriddlyResult<T> : GriddlyResult<T>
13
13
Func < IDbConnection > _getConnection ;
14
14
Func < IDbTransaction > _getTransaction ;
15
15
string _sql ;
16
+ string _outerSqlTemplate ;
16
17
object _param ;
17
18
Func < IDbConnection , IDbTransaction , string , object , IEnumerable < T > > _map ;
18
19
Action < IDbConnection , IDbTransaction , IList < T > > _massage ;
@@ -21,12 +22,13 @@ public class DapperGriddlyResult<T> : GriddlyResult<T>
21
22
bool _fixedSort ;
22
23
static readonly bool _hasOverallCount = typeof ( IHasOverallCount ) . IsAssignableFrom ( typeof ( T ) ) ;
23
24
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}" )
25
26
: base ( null )
26
27
{
27
28
_getConnection = getConnection ;
28
29
_sql = sql ;
29
30
_param = param ;
31
+ _outerSqlTemplate = outerSqlTemplate ;
30
32
31
33
if ( map == null )
32
34
_map = DefaultMap ;
@@ -59,7 +61,8 @@ public override void PopulateSummaryValues(GriddlySettings<T> settings)
59
61
aggregateExpression . AppendFormat ( "{0}({1}) AS _a{2}" , col . SummaryFunction , col . ExpressionString , i ) ;
60
62
}
61
63
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 ) ) ;
63
66
64
67
try
65
68
{
@@ -82,7 +85,8 @@ public override long GetCount()
82
85
{
83
86
if ( _overallCount == null )
84
87
{
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 ) ) ;
86
90
87
91
try
88
92
{
@@ -118,14 +122,16 @@ SELECT COUNT(0) AS OverallCount FROM _data
118
122
)
119
123
SELECT * FROM _data CROSS APPLY _count " + ( _fixedSort ? "" : "ORDER BY {1}" ) + " OFFSET {2} ROWS FETCH NEXT {3} ROWS ONLY" ;
120
124
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 ) ) ;
122
127
123
128
return ExecuteQuery ( sql , _param ) ;
124
129
}
125
130
126
131
public override IEnumerable < T > GetAll ( SortField [ ] sortFields )
127
132
{
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 ) ) ) ;
129
135
130
136
return ExecuteQuery ( sql , _param ) ;
131
137
}
0 commit comments