Skip to content

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

Open
wants to merge 35 commits into
base: main
Choose a base branch
from

Conversation

cincuranet
Copy link
Contributor

@cincuranet cincuranet commented May 29, 2025

Contributes to #36101.
Closes #34347.

@cincuranet cincuranet force-pushed the primitive branch 3 times, most recently from 4f67357 to b878f5d Compare May 30, 2025 14:13
@cincuranet cincuranet requested review from a team and Copilot June 2, 2025 10:36
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR extends EF Core to support translating primitive collections into multiple SQL parameters instead of a single parameter or JSON, driven by a new ParameterizedCollectionTranslationMode.

  • Changed parameter value storage and method signatures from IReadOnlyDictionary<string, object?> to mutable Dictionary<string, object?>.
  • Introduced ParameterizedCollectionTranslationMode enum and threaded it through SQL processors, visitors, and the DbContext options builder.
  • Updated SQL generation in SQLite for multi-row VALUES (wrapping in a sub-SELECT) and enhanced JSON/OPENJSON logic for SQL Server.

Reviewed Changes

Copilot reviewed 65 out of 65 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/EFCore/Query/Internal/IParameterValues.cs Changed interface property to return mutable Dictionary.
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs Updated Parameters.ParameterValues to Dictionary.
src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitor.cs Added TryTranslate helper and new JSON index translation.
src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGenerator.cs Wrapped multi-row VALUES in SELECT * FROM (…).
src/EFCore.Relational/Internal/ParameterizedCollectionTranslationMode.cs Added new enum member ParameterizeExpanded.
src/EFCore.Relational/Infrastructure/RelationalDbContextOptionsBuilder.cs Added TranslateParameterizedCollectionsToExpandedParameters option.
Multiple files across SqlNullabilityProcessor, SQL Server/SQLite processors and factories Threaded new mode through constructors and method signatures.
Comments suppressed due to low confidence (2)

src/EFCore.Relational/Query/SqlNullabilityProcessor.cs:123

  • [nitpick] This VisitExtension override now handles multiple translation modes with nested logic; consider extracting each mode case into its own helper method to improve readability and reduce method complexity.
protected override Expression VisitExtension(Expression node)

src/EFCore.Relational/Infrastructure/RelationalDbContextOptionsBuilder.cs:226

  • New builder option for expanded parameters was added; ensure there are unit or integration tests covering this mode to verify correct SQL translation.
public virtual TBuilder TranslateParameterizedCollectionsToExpandedParameters()

@cincuranet cincuranet force-pushed the primitive branch 2 times, most recently from eed2aa8 to 0be8385 Compare June 2, 2025 10:42
@cincuranet cincuranet marked this pull request as ready for review June 2, 2025 10:47
Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see this, thanks @cincuranet. Let's iterate and get it to the finish line.

Of course OK to split things out to later PRs, we can discusss.

@cincuranet cincuranet force-pushed the primitive branch 3 times, most recently from bc2e8a0 to d4def1b Compare June 19, 2025 06:18
@cincuranet cincuranet requested a review from roji June 23, 2025 09:03
Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really close now, see essentially nits and doc comments.

subquery.Orderings,
subquery.Offset,
subquery.Limit));
if (subquery is { Tables: [ValuesExpression { RowValues: { } rowValues }] })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still missing context on this (like what changed in this PR that now requires this) - maybe a bit more contextual docs make sense.

/// 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.
/// Indicates how parametrized collections are translated into SQL.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Indicates how parametrized collections are translated into SQL.
/// Indicates how parameterized collections are translated into SQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider changing the default handling of parameterized collections (back to constantization, RECOMPILE, inline collection of parameters...)
2 participants