Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move fake ORDER BY clause to SQL Server provider #21187

Merged
merged 1 commit into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/EFCore.Relational/Query/QuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,6 @@ protected virtual void GenerateOrderings([NotNull] SelectExpression selectExpres
GenerateList(orderings, e => Visit(e));
}
}
else if (selectExpression.Offset != null)
{
_relationalCommandBuilder.AppendLine().Append("ORDER BY (SELECT 1)");
}
}

/// <summary>
Expand Down
20 changes: 20 additions & 0 deletions src/EFCore.SqlServer/Query/Internal/SqlServerQuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ protected override void GenerateTop(SelectExpression selectExpression)
}
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override void GenerateOrderings(SelectExpression selectExpression)
{
Check.NotNull(selectExpression, nameof(selectExpression));

base.GenerateOrderings(selectExpression);

// In SQL Server, if an offset is specified, then an ORDER BY clause must also exist.
// Generate a fake one.
if (!selectExpression.Orderings.Any() && selectExpression.Offset != null)
{
Sql.AppendLine().Append("ORDER BY (SELECT 1)");
}
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ SELECT COUNT(*)
FROM (
SELECT ""c"".""CustomerID"", ""c"".""Address"", ""c"".""City"", ""c"".""CompanyName"", ""c"".""ContactName"", ""c"".""ContactTitle"", ""c"".""Country"", ""c"".""Fax"", ""c"".""Phone"", ""c"".""PostalCode"", ""c"".""Region""
FROM ""Customers"" AS ""c""
ORDER BY (SELECT 1)
LIMIT -1 OFFSET @__p_0
) AS ""t""");
}
Expand Down