Skip to content

Commit f0d952a

Browse files
committed
Minor optimization.
1 parent e9779c1 commit f0d952a

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/NHibernate/Dialect/MsSql2005DialectQueryPager.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,12 @@ private static void AppendSortExpressions(Dictionary<SqlString, SqlString> alias
156156
}
157157

158158
SqlString sortExpression = RemoveSortOrderDirection(sortExpressions[i]);
159-
if (aliasToColumn.ContainsKey(sortExpression))
159+
SqlString s;
160+
if (aliasToColumn.TryGetValue(sortExpression, out s))
160161
{
161-
result.Add(aliasToColumn[sortExpression]);
162+
result.Add(s);
162163
}
163-
else
164+
else
164165
{
165166
result.Add(sortExpression);
166167
}
@@ -196,21 +197,25 @@ private static void AppendSortExpressionsForDistinct(Dictionary<SqlString, SqlSt
196197
if (sortExpression.StartsWithCaseInsensitive("CURRENT_TIMESTAMP"))
197198
result.Add(sortExpression);
198199

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-
}
209200
else
210201
{
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+
}
214219
}
215220

216221
if (sortExpressions[i].Trim().EndsWithCaseInsensitive("desc"))

0 commit comments

Comments
 (0)