@@ -920,8 +920,8 @@ static Expression RemoveConvert(Expression expression)
920
920
var actualParentIdentifier = _identifier . Take ( outerSelectExpression . _identifier . Count ) . ToList ( ) ;
921
921
for ( var j = 0 ; j < actualParentIdentifier . Count ; j ++ )
922
922
{
923
- AppendOrdering ( new OrderingExpression ( actualParentIdentifier [ j ] . Column , ascending : true ) ) ;
924
- outerSelectExpression . AppendOrdering (
923
+ AppendOrderingInternal ( new OrderingExpression ( actualParentIdentifier [ j ] . Column , ascending : true ) ) ;
924
+ outerSelectExpression . AppendOrderingInternal (
925
925
new OrderingExpression ( outerSelectExpression . _identifier [ j ] . Column , ascending : true ) ) ;
926
926
}
927
927
@@ -1860,6 +1860,11 @@ private static void PopulateGroupByTerms(
1860
1860
/// <param name="orderingExpression">An ordering expression to use for ordering.</param>
1861
1861
public void ApplyOrdering ( OrderingExpression orderingExpression )
1862
1862
{
1863
+ if ( Limit is SqlConstantExpression { Value : 1 } )
1864
+ {
1865
+ return ;
1866
+ }
1867
+
1863
1868
if ( IsDistinct
1864
1869
|| Limit != null
1865
1870
|| Offset != null )
@@ -1877,14 +1882,21 @@ public void ApplyOrdering(OrderingExpression orderingExpression)
1877
1882
/// <param name="orderingExpression">An ordering expression to use for ordering.</param>
1878
1883
public void AppendOrdering ( OrderingExpression orderingExpression )
1879
1884
{
1880
- if ( ! _orderings . Any ( o => o . Expression . Equals ( orderingExpression . Expression ) ) )
1885
+ if ( Limit is SqlConstantExpression { Value : 1 } )
1881
1886
{
1882
- AppendOrderingInternal ( orderingExpression ) ;
1887
+ return ;
1883
1888
}
1889
+
1890
+ AppendOrderingInternal ( orderingExpression ) ;
1884
1891
}
1885
1892
1886
1893
private void AppendOrderingInternal ( OrderingExpression orderingExpression )
1887
- => _orderings . Add ( orderingExpression . Update ( orderingExpression . Expression ) ) ;
1894
+ {
1895
+ if ( ! _orderings . Any ( o => o . Expression . Equals ( orderingExpression . Expression ) ) )
1896
+ {
1897
+ _orderings . Add ( orderingExpression ) ;
1898
+ }
1899
+ }
1888
1900
1889
1901
/// <summary>
1890
1902
/// Reverses the existing orderings on the <see cref="SelectExpression" />.
0 commit comments