-
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.
Fix to #18492 - Query: inject SearchConditionConvertingExpressionVisi…
…tor into ParameterValueBasedSelectExpressionOptimizer Using DI to create parameter value based postprocessor, which allows for provider-specific optimizations, including SearchConditionConvertingExpressionVisitor Resolves #18492 Resolved #18940
- Loading branch information
Showing
17 changed files
with
247 additions
and
93 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
23 changes: 23 additions & 0 deletions
23
src/EFCore.Relational/Query/IRelationalParameterBasedQueryTranslationPostprocessorFactory.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,23 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.EntityFrameworkCore.Query.Internal; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query | ||
{ | ||
/// <summary> | ||
/// <para> | ||
/// A factory for creating <see cref="RelationalParameterBasedQueryTranslationPostprocessor" /> instances. | ||
/// </para> | ||
/// <para> | ||
/// The service lifetime is <see cref="ServiceLifetime.Singleton" />. This means a single instance | ||
/// is used by many <see cref="DbContext" /> instances. The implementation must be thread-safe. | ||
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped" />. | ||
/// </para> | ||
/// </summary> | ||
public interface IRelationalParameterBasedQueryTranslationPostprocessorFactory | ||
{ | ||
RelationalParameterBasedQueryTranslationPostprocessor Create(bool useRelationalNulls); | ||
} | ||
} |
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
93 changes: 93 additions & 0 deletions
93
...ional/Query/Internal/RelationalParameterBasedQueryTranslationPostprocessorDependencies.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,93 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
using Microsoft.EntityFrameworkCore.Utilities; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query.Internal | ||
{ | ||
/// <summary> | ||
/// <para> | ||
/// Service dependencies parameter class for <see cref="RelationalParameterBasedQueryTranslationPostprocessorFactory" /> | ||
/// </para> | ||
/// <para> | ||
/// This type is typically used by database providers (and other extensions). It is generally | ||
/// not used in application code. | ||
/// </para> | ||
/// <para> | ||
/// Do not construct instances of this class directly from either provider or application code as the | ||
/// constructor signature may change as new dependencies are added. Instead, use this type in | ||
/// your constructor so that an instance will be created and injected automatically by the | ||
/// dependency injection container. To create an instance with some dependent services replaced, | ||
/// first resolve the object from the dependency injection container, then replace selected | ||
/// services using the 'With...' methods. Do not call the constructor at any point in this process. | ||
/// </para> | ||
/// <para> | ||
/// The service lifetime is <see cref="ServiceLifetime.Singleton" />. This means a single instance | ||
/// is used by many <see cref="DbContext" /> instances. The implementation must be thread-safe. | ||
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped" />. | ||
/// </para> | ||
/// </summary> | ||
public sealed class RelationalParameterBasedQueryTranslationPostprocessorDependencies | ||
{ | ||
/// <summary> | ||
/// <para> | ||
/// Creates the service dependencies parameter object for a <see cref="RelationalParameterBasedQueryTranslationPostprocessorFactory" />. | ||
/// </para> | ||
/// <para> | ||
/// Do not call this constructor directly from either provider or application code as it may change | ||
/// as new dependencies are added. Instead, use this type in your constructor so that an instance | ||
/// will be created and injected automatically by the dependency injection container. To create | ||
/// an instance with some dependent services replaced, first resolve the object from the dependency | ||
/// injection container, then replace selected services using the 'With...' methods. Do not call | ||
/// the constructor at any point in this process. | ||
/// </para> | ||
/// <para> | ||
/// 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. | ||
/// </para> | ||
/// </summary> | ||
[EntityFrameworkInternal] | ||
public RelationalParameterBasedQueryTranslationPostprocessorDependencies( | ||
[NotNull] ISqlExpressionFactory sqlExpressionFactory, | ||
[NotNull] IParameterNameGeneratorFactory parameterNameGeneratorFactory) | ||
{ | ||
Check.NotNull(sqlExpressionFactory, nameof(sqlExpressionFactory)); | ||
Check.NotNull(parameterNameGeneratorFactory, nameof(parameterNameGeneratorFactory)); | ||
|
||
SqlExpressionFactory = sqlExpressionFactory; | ||
ParameterNameGeneratorFactory = parameterNameGeneratorFactory; | ||
} | ||
|
||
/// <summary> | ||
/// Sql expression factory. | ||
/// </summary> | ||
public ISqlExpressionFactory SqlExpressionFactory { get; } | ||
|
||
/// <summary> | ||
/// Parameter name generator factory. | ||
/// </summary> | ||
public IParameterNameGeneratorFactory ParameterNameGeneratorFactory { get; } | ||
|
||
/// <summary> | ||
/// Clones this dependency parameter object with one service replaced. | ||
/// </summary> | ||
/// <param name="sqlExpressionFactory"> A replacement for the current dependency of this type. </param> | ||
/// <returns> A new parameter object with the given service replaced. </returns> | ||
public RelationalParameterBasedQueryTranslationPostprocessorDependencies With(ISqlExpressionFactory sqlExpressionFactory) | ||
=> new RelationalParameterBasedQueryTranslationPostprocessorDependencies(sqlExpressionFactory, ParameterNameGeneratorFactory); | ||
|
||
/// <summary> | ||
/// Clones this dependency parameter object with one service replaced. | ||
/// </summary> | ||
/// <param name="parameterNameGeneratorFactory"> A replacement for the current dependency of this type. </param> | ||
/// <returns> A new parameter object with the given service replaced. </returns> | ||
public RelationalParameterBasedQueryTranslationPostprocessorDependencies With(IParameterNameGeneratorFactory parameterNameGeneratorFactory) | ||
=> new RelationalParameterBasedQueryTranslationPostprocessorDependencies(SqlExpressionFactory, parameterNameGeneratorFactory); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...Relational/Query/Internal/RelationalParameterBasedQueryTranslationPostprocessorFactory.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,18 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query.Internal | ||
{ | ||
public class RelationalParameterBasedQueryTranslationPostprocessorFactory : IRelationalParameterBasedQueryTranslationPostprocessorFactory | ||
{ | ||
private readonly RelationalParameterBasedQueryTranslationPostprocessorDependencies _dependencies; | ||
|
||
public RelationalParameterBasedQueryTranslationPostprocessorFactory(RelationalParameterBasedQueryTranslationPostprocessorDependencies dependencies) | ||
{ | ||
_dependencies = dependencies; | ||
} | ||
|
||
public virtual RelationalParameterBasedQueryTranslationPostprocessor Create(bool useRelationalNulls) | ||
=> new RelationalParameterBasedQueryTranslationPostprocessor(_dependencies, useRelationalNulls); | ||
} | ||
} |
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
Oops, something went wrong.