From 2d262caa07bd832657803b4e86d5784ed5190da2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Mar 2026 19:41:48 +0000 Subject: [PATCH 1/2] Initial plan From c4cbb7e070917bc41b48cb31cb0f4cf7a4218a00 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Mar 2026 20:10:25 +0000 Subject: [PATCH 2/2] Fix nullable value type coercion in ExpressionTreeFuncletizer.ProcessEvaluatableRoot Co-authored-by: roji <1862641+roji@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/efcore/sessions/1452f6d8-60ff-43d5-9380-319e917be42b --- .../Query/Internal/ExpressionTreeFuncletizer.cs | 7 ++++++- .../BulkUpdates/NorthwindBulkUpdatesTestBase.cs | 10 ++++++++++ .../NorthwindBulkUpdatesSqlServerTest.cs | 13 +++++++++++++ .../BulkUpdates/NorthwindBulkUpdatesSqliteTest.cs | 12 ++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs b/src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs index ade3e0e7450..0f4c0c5602e 100644 --- a/src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs +++ b/src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs @@ -2006,10 +2006,15 @@ private static StateType CombineStateTypes(StateType stateType1, StateType state return evaluatableRoot; } - return ConvertIfNeeded( + var constantExpression = ConvertIfNeeded( Constant(value, value is null ? evaluatableRoot.Type : value.GetType()), evaluatableRoot.Type); + // ConvertIfNeeded calls Visit which may have modified _state; reset it since we've already evaluated this root as a constant. + state = State.NoEvaluatability; + + return constantExpression; + bool TryHandleNonEvaluatableAsRoot(Expression root, State state, bool asParameter, [NotNullWhen(true)] out Expression? result) { switch (root) diff --git a/test/EFCore.Specification.Tests/BulkUpdates/NorthwindBulkUpdatesTestBase.cs b/test/EFCore.Specification.Tests/BulkUpdates/NorthwindBulkUpdatesTestBase.cs index f0310595bb0..8380b1485c7 100644 --- a/test/EFCore.Specification.Tests/BulkUpdates/NorthwindBulkUpdatesTestBase.cs +++ b/test/EFCore.Specification.Tests/BulkUpdates/NorthwindBulkUpdatesTestBase.cs @@ -392,6 +392,16 @@ public virtual Task Update_Where_set_constant_via_lambda(bool async) rowsAffectedCount: 8, (b, a) => Assert.All(a, c => Assert.Equal("Updated", c.ContactName))); + [ConditionalTheory, MemberData(nameof(IsAsyncData))] + public virtual Task Update_Where_set_nullable_int_constant_via_discard_lambda(bool async) + => AssertUpdate( + async, + ss => ss.Set().Where(p => p.ProductID < 5), + e => e, + s => s.SetProperty(c => c.SupplierID, _ => 1), + rowsAffectedCount: 4, + (b, a) => Assert.All(a, p => Assert.Equal(1, p.SupplierID))); + [ConditionalTheory, MemberData(nameof(IsAsyncData))] public virtual async Task Update_Where_parameter_set_constant(bool async) { diff --git a/test/EFCore.SqlServer.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqlServerTest.cs index dceebdc2e9d..4b675a62c24 100644 --- a/test/EFCore.SqlServer.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqlServerTest.cs @@ -688,6 +688,19 @@ WHERE [c].[CustomerID] LIKE N'F%' """); } + public override async Task Update_Where_set_nullable_int_constant_via_discard_lambda(bool async) + { + await base.Update_Where_set_nullable_int_constant_via_discard_lambda(async); + + AssertExecuteUpdateSql( + """ +UPDATE [p] +SET [p].[SupplierID] = 1 +FROM [Products] AS [p] +WHERE [p].[ProductID] < 5 +"""); + } + public override async Task Update_Where_parameter_set_constant(bool async) { await base.Update_Where_parameter_set_constant(async); diff --git a/test/EFCore.Sqlite.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqliteTest.cs index c5754a9de44..e72e6c1d147 100644 --- a/test/EFCore.Sqlite.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqliteTest.cs @@ -667,6 +667,18 @@ public override async Task Update_Where_set_constant_via_lambda(bool async) """); } + public override async Task Update_Where_set_nullable_int_constant_via_discard_lambda(bool async) + { + await base.Update_Where_set_nullable_int_constant_via_discard_lambda(async); + + AssertExecuteUpdateSql( + """ +UPDATE "Products" AS "p" +SET "SupplierID" = 1 +WHERE "p"."ProductID" < 5 +"""); + } + public override async Task Update_Where_parameter_set_constant(bool async) { await base.Update_Where_parameter_set_constant(async);