-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Handle primitive collections as multiple parameters. #36157
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
Merged
+2,621
−2,693
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,34 @@ | ||
// 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; | ||
|
||
/// <summary> | ||
/// Methods that are useful in application code. For example, referencing a shadow state property in a LINQ query. | ||
/// </summary> | ||
/// <remarks> | ||
/// See <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see> and | ||
/// <see href="https://aka.ms/efcore-docs-efproperty">Using EF.Property in EF Core queries</see> for more information and examples. | ||
/// </remarks> | ||
public static class EFExtensions | ||
{ | ||
/// <summary> | ||
/// Methods that are useful in application code. For example, referencing a shadow state property in a LINQ query. | ||
/// </summary> | ||
/// <remarks> | ||
/// See <see href="https://aka.ms/efcore-docs-database-functions">Database functions</see> and | ||
/// <see href="https://aka.ms/efcore-docs-efproperty">Using EF.Property in EF Core queries</see> for more information and examples. | ||
/// </remarks> | ||
extension(EF) | ||
{ | ||
/// <summary> | ||
/// Within the context of an EF LINQ query, forces its argument to be inserted into the query as a multiple parameter expressions. | ||
/// </summary> | ||
/// <remarks>Note that this is a static method accessed through the top-level <see cref="EF" /> static type.</remarks> | ||
/// <typeparam name="T">The type of collection element.</typeparam> | ||
/// <param name="argument">The collection to be integrated as parameters into the query.</param> | ||
/// <returns>The same value for further use in the query.</returns> | ||
public static IEnumerable<T> MultipleParameters<T>(IEnumerable<T> argument) | ||
=> throw new InvalidOperationException(RelationalStrings.EFMultipleParametersInvoked); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
29 changes: 0 additions & 29 deletions
29
src/EFCore.Relational/Internal/ParameterizedCollectionTranslationMode.cs
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,56 @@ | ||
// 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; | ||
|
||
/// <summary> | ||
/// Indicates how parameterized collections are translated into SQL. | ||
/// </summary> | ||
public enum ParameterizedCollectionMode | ||
{ | ||
/// <summary> | ||
/// Instructs EF to translate the collection to a set of constants: | ||
/// <c>WHERE [x].[Id] IN (1, 2, 3)</c>. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// This can produce better query plans for certain query types, but can also lead to query | ||
/// plan bloat. | ||
/// </para> | ||
/// <para> | ||
/// Note that it's possible to cause EF to translate a specific collection in a specific query to constants by wrapping the | ||
/// parameterized collection in <see cref="EF.Constant{T}" />: <c>Where(x => EF.Constant(ids).Contains(x.Id)</c>. This overrides | ||
/// the default. | ||
/// </para> | ||
/// </remarks> | ||
Constants, | ||
|
||
/// <summary> | ||
/// Instructs EF to translate the collection to a single array-like parameter: | ||
/// <c>WHERE [x].[Id] IN (SELECT [i].[value] FROM OPENJSON(@ids) ...)</c>. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
cincuranet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// This can produce suboptimal query plans for certain query types. | ||
/// </para> | ||
/// <para> | ||
/// Note that it's possible to cause EF to translate a specific collection in a specific query to parameter by wrapping the | ||
/// parameterized collection in <see cref="EF.Parameter{T}" />: <c>Where(x => EF.Parameter(ids).Contains(x.Id)</c>. This overrides | ||
/// the default. | ||
/// </para> | ||
/// </remarks> | ||
Parameter, | ||
|
||
/// <summary> | ||
/// Instructs EF to translate the collection to a set of parameters: | ||
/// <c>WHERE [x].[Id] IN (@ids1, @ids2, @ids3)</c>. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// Note that it's possible to cause EF to translate a specific collection in a specific query to parameter by wrapping the | ||
/// parameterized collection in <see cref="EFExtensions.MultipleParameters{T}" />: <c>Where(x => EF.MultipleParameters(ids).Contains(x.Id)</c>. This overrides | ||
/// the default. | ||
/// </para> | ||
/// </remarks> | ||
MultipleParameters, | ||
} |
6 changes: 6 additions & 0 deletions
6
src/EFCore.Relational/Properties/RelationalStrings.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.