-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SqlServer: Throw for split query with skip without order by (#28056)
Resolves #21202
- Loading branch information
Showing
8 changed files
with
181 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/EFCore.SqlServer/Query/Internal/SqlServerQueryTranslationPostprocessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.EntityFrameworkCore.Query.SqlExpressions; | ||
using Microsoft.EntityFrameworkCore.SqlServer.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; | ||
|
||
/// <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> | ||
public class SqlServerQueryTranslationPostprocessor : RelationalQueryTranslationPostprocessor | ||
{ | ||
private readonly SkipWithoutOrderByInSplitQueryVerifyingExpressionVisitor | ||
_skipWithoutOrderByInSplitQueryVerifyingExpressionVisitor = new(); | ||
|
||
/// <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> | ||
public SqlServerQueryTranslationPostprocessor( | ||
QueryTranslationPostprocessorDependencies dependencies, | ||
RelationalQueryTranslationPostprocessorDependencies relationalDependencies, | ||
QueryCompilationContext queryCompilationContext) | ||
: base(dependencies, relationalDependencies, queryCompilationContext) | ||
{ | ||
} | ||
|
||
/// <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> | ||
public override Expression Process(Expression query) | ||
{ | ||
var result = base.Process(query); | ||
|
||
_skipWithoutOrderByInSplitQueryVerifyingExpressionVisitor.Visit(result); | ||
|
||
return result; | ||
} | ||
|
||
private sealed class SkipWithoutOrderByInSplitQueryVerifyingExpressionVisitor : ExpressionVisitor | ||
{ | ||
[return: NotNullIfNotNull("expression")] | ||
public override Expression? Visit(Expression? expression) | ||
{ | ||
switch (expression) | ||
{ | ||
case ShapedQueryExpression shapedQueryExpression: | ||
Visit(shapedQueryExpression.ShaperExpression); | ||
return shapedQueryExpression; | ||
|
||
case RelationalSplitCollectionShaperExpression relationalSplitCollectionShaperExpression: | ||
foreach (var table in relationalSplitCollectionShaperExpression.SelectExpression.Tables) | ||
{ | ||
Visit(table); | ||
} | ||
|
||
Visit(relationalSplitCollectionShaperExpression.InnerShaper); | ||
|
||
return relationalSplitCollectionShaperExpression; | ||
|
||
case SelectExpression selectExpression | ||
when selectExpression.Offset != null | ||
&& selectExpression.Orderings.Count == 0: | ||
throw new InvalidOperationException(SqlServerStrings.SplitQueryOffsetWithoutOrderBy); | ||
|
||
|
||
default: | ||
return base.Visit(expression); | ||
} | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/EFCore.SqlServer/Query/Internal/SqlServerQueryTranslationPostprocessorFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; | ||
|
||
/// <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> | ||
public class SqlServerQueryTranslationPostprocessorFactory : IQueryTranslationPostprocessorFactory | ||
{ | ||
/// <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> | ||
public SqlServerQueryTranslationPostprocessorFactory( | ||
QueryTranslationPostprocessorDependencies dependencies, | ||
RelationalQueryTranslationPostprocessorDependencies relationalDependencies) | ||
{ | ||
Dependencies = dependencies; | ||
RelationalDependencies = relationalDependencies; | ||
} | ||
|
||
/// <summary> | ||
/// Dependencies for this service. | ||
/// </summary> | ||
protected virtual QueryTranslationPostprocessorDependencies Dependencies { get; } | ||
|
||
/// <summary> | ||
/// Relational provider-specific dependencies for this service. | ||
/// </summary> | ||
protected virtual RelationalQueryTranslationPostprocessorDependencies RelationalDependencies { get; } | ||
|
||
/// <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> | ||
public virtual QueryTranslationPostprocessor Create(QueryCompilationContext queryCompilationContext) | ||
=> new SqlServerQueryTranslationPostprocessor( | ||
Dependencies, | ||
RelationalDependencies, | ||
queryCompilationContext); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.