Skip to content

[release/10.0] Fix ExecuteUpdate over scalar projections#37791

Open
roji wants to merge 1 commit intodotnet:release/10.0from
roji:37771
Open

[release/10.0] Fix ExecuteUpdate over scalar projections#37791
roji wants to merge 1 commit intodotnet:release/10.0from
roji:37771

Conversation

@roji
Copy link
Member

@roji roji commented Feb 24, 2026

Fixes #37771

Description

When ExecuteUpdate is preceded by a Select that projects to a scalar-only anonymous type (e.g. select new { p.Used, n.Qty }), the query fails with "The following lambda argument to 'SetProperty' does not represent a valid property to be set". This happens because the fix for #37247 (PR #37262) unconditionally applies the pending selector before processing ExecuteUpdate setters. When the pending selector contains only scalar values (no entity references), applying it loses the connection between the projected scalars and the original entity properties, so ExecuteUpdate can no longer resolve which column to update.

The fix guards this pending selector application: it is only applied when the snapshot of the pending selector contains entity/structural type references (i.e. is not a DefaultExpression). When all projected members are scalars, the pending selector is skipped, preserving the original entity property binding.

Customer impact

Any ExecuteUpdate query that is preceded by a Select projecting to an anonymous type containing only scalar properties fails at query translation time. No data corruption occurs — the query throws before executing. There is no feasible workaround other than using the quirk to disable #37247, downgrading to 10.0.1 or restructuring the query to avoid the scalar projection.

How found

User reported on 10.0.2/10.0.3. A second user reported a potentially related issue in the comments. 1 upvote, 2 comment authors affected.

Regression

Yes. Regression from 10.0.1, introduced in 10.0.2 by PR #37262 (fix for #37247).

Testing

4 new tests added (2 test methods × sync/async): one for scalar-only anonymous projection, one for mixed entity+scalar anonymous projection.

Risk

Very low. The product code change is a single conditional guard (wrapping existing code in if (newStructure is not DefaultExpression)). The original #37247 fix continues to work — its existing test still passes. Quirk added.

Copilot AI review requested due to automatic review settings February 24, 2026 12:41
@roji roji requested a review from a team as a code owner February 24, 2026 12:41
Copy link

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

Fixes a regression where ExecuteUpdate fails when preceded by a Select projecting to a scalar-only anonymous type, by avoiding application of the pending selector when it contains only scalar projections.

Changes:

  • Guard pending selector application in NavigationExpandingExpressionVisitor.ProcessExecuteUpdate based on SnapshotExpression structure (and add an Issue37771 quirk switch).
  • Add relational spec tests covering scalar-only and mixed entity+scalar anonymous projections before ExecuteUpdate.
  • Add provider-specific SQL baselines for the new tests (SQLite, SQL Server).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs Skips applying the pending selector when its snapshot is a DefaultExpression, preserving property binding for scalar-only projections.
test/EFCore.Relational.Specification.Tests/BulkUpdates/NorthwindBulkUpdatesRelationalTestBase.cs Adds new tests for ExecuteUpdate over scalar-only and mixed projections (#37771).
test/EFCore.Sqlite.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqliteTest.cs Adds SQLite SQL baselines for the new tests.
test/EFCore.SqlServer.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqlServerTest.cs Adds SQL Server SQL baselines for the new tests.

@AndriySvyryd AndriySvyryd changed the title Fix ExecuteUpdate over scalar projections [release/10.0] Fix ExecuteUpdate over scalar projections Feb 25, 2026
@AndriySvyryd AndriySvyryd requested a review from artl93 February 25, 2026 04:22
Copy link
Member

@artl93 artl93 left a comment

Choose a reason for hiding this comment

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

Approved. Servicing regression, customer reported.

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.

4 participants