@@ -156,11 +156,12 @@ private static void AppendSortExpressions(Dictionary<SqlString, SqlString> alias
156
156
}
157
157
158
158
SqlString sortExpression = RemoveSortOrderDirection ( sortExpressions [ i ] ) ;
159
- if ( aliasToColumn . ContainsKey ( sortExpression ) )
159
+ SqlString s ;
160
+ if ( aliasToColumn . TryGetValue ( sortExpression , out s ) )
160
161
{
161
- result . Add ( aliasToColumn [ sortExpression ] ) ;
162
+ result . Add ( s ) ;
162
163
}
163
- else
164
+ else
164
165
{
165
166
result . Add ( sortExpression ) ;
166
167
}
@@ -196,21 +197,25 @@ private static void AppendSortExpressionsForDistinct(Dictionary<SqlString, SqlSt
196
197
if ( sortExpression . StartsWithCaseInsensitive ( "CURRENT_TIMESTAMP" ) )
197
198
result . Add ( sortExpression ) ;
198
199
199
- else if ( columnToAlias . ContainsKey ( sortExpression ) )
200
- {
201
- result . Add ( "q_." ) ;
202
- result . Add ( columnToAlias [ sortExpression ] ) ;
203
- }
204
- else if ( columnToAlias . ContainsValue ( sortExpression ) ) // When a distinct query is paged the sortexpressions could already be aliased.
205
- {
206
- result . Add ( "q_." ) ;
207
- result . Add ( sortExpression ) ;
208
- }
209
200
else
210
201
{
211
- throw new HibernateException (
212
- "The dialect was unable to perform paging of a statement that requires distinct results, and "
213
- + "is ordered by a column that is not included in the result set of the query." ) ;
202
+ SqlString value ;
203
+ if ( columnToAlias . TryGetValue ( sortExpression , out value ) )
204
+ {
205
+ result . Add ( "q_." ) ;
206
+ result . Add ( value ) ;
207
+ }
208
+ else if ( columnToAlias . ContainsValue ( sortExpression ) ) // When a distinct query is paged the sortexpressions could already be aliased.
209
+ {
210
+ result . Add ( "q_." ) ;
211
+ result . Add ( sortExpression ) ;
212
+ }
213
+ else
214
+ {
215
+ throw new HibernateException (
216
+ "The dialect was unable to perform paging of a statement that requires distinct results, and "
217
+ + "is ordered by a column that is not included in the result set of the query." ) ;
218
+ }
214
219
}
215
220
216
221
if ( sortExpressions [ i ] . Trim ( ) . EndsWithCaseInsensitive ( "desc" ) )
0 commit comments