{"record":{"id":"a123c818eabed45e","repo":"dotnet/efcore","slug":"executeupdate-cannot-currently-set-a-property-in-a123c8","errorCode":null,"errorMessage":"'ExecuteUpdate' cannot currently set a property in a JSON column to arbitrary expressions; only constants, parameters and other JSON properties are supported; see https://github.com/dotnet/efcore/issues/36688.","messagePattern":"'ExecuteUpdate' cannot currently set a property in a JSON column to arbitrary expressions; only constants, parameters and other JSON properties are supported; see https://github\\.com/dotnet/efcore/issues/36688\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.ExecuteUpdate.cs","lineNumber":391,"sourceCode":"                    var typeMapping = jsonScalar.TypeMapping;\n                    Check.DebugAssert(typeMapping is not null);\n\n                    // We should never see a JsonScalarExpression without a path - that means we're mapping a JSON scalar directly to a relational column.\n                    // This is in theory possible (e.g. map a DateTime to a 'json' column with a single string timestamp representation inside, instead of to\n                    // SQL Server datetime2), but contrived and unsupported.\n                    Check.DebugAssert(jsonScalar.Path.Count > 0);\n\n                    ProcessColumn(jsonColumn, targetProperty);\n\n                    var translatedValue = TranslateScalarSetterValueSelector(source, valueSelector, jsonScalar.Type, typeMapping);\n\n                    // We now have the relational scalar expression for the value; but we need the JSON representation to pass to the provider's JSON modification\n                    // function (e.g. SQL Server JSON_MODIFY()).\n                    // For example, for a DateTime we'd have e.g. a SqlConstantExpression containing a DateTime instance, but we need a string containing\n                    // the JSON-encoded ISO8601 representation.\n                    if (!TrySerializeScalarToJson(jsonScalar, translatedValue, out var jsonValue))\n                    {\n                        throw new InvalidOperationException(\n                            translatedValue is ColumnExpression\n                                ? RelationalStrings.ExecuteUpdateCannotSetJsonPropertyToNonJsonColumn\n                                : RelationalStrings.ExecuteUpdateCannotSetJsonPropertyToArbitraryExpression);\n                    }\n\n                    // We now have a serialized JSON value (number, string or bool) - generate a setter for it.\n                    GenerateJsonPartialUpdateSetterWrapper(jsonScalar, jsonColumn, jsonValue);\n                    continue;\n                }\n\n                case StructuralTypeShaperExpression { ValueBufferExpression: JsonQueryExpression jsonQuery }:\n                    ProcessStructuralJsonSetter(jsonQuery);\n                    continue;\n\n                case CollectionResultExpression { QueryExpression: JsonQueryExpression jsonQuery }:\n                    ProcessStructuralJsonSetter(jsonQuery);\n                    continue;\n","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.ExecuteUpdate.cs#L373-L409","documentation":"Sibling of 606, same JsonScalarExpression case of TrySerializeScalarToJson failing, but here the translatedValue is NOT a ColumnExpression — it is some arbitrary SQL expression the JSON serializer cannot handle. JSON modification functions only accept constants, parameters, or other JSON properties.","triggerScenarios":"SetProperty into a JSON scalar path whose value selector translates to a function call, arithmetic, or any non-constant/non-parameter expression (e.g. SetProperty(e => e.Config.Score, e => e.A + e.B)).","commonSituations":"Computing the new JSON value inline; using database functions inside the value selector of a JSON setter.","solutions":["Compute the value in application code and pass it as a parameter/constant.","Restrict JSON-setter value selectors to constants, captured variables (parameters), or another JSON property reference.","Track #36688 for broader expression support."],"exampleFix":"// before\n.ExecuteUpdate(s => s.SetProperty(e => e.Config.Score, e => e.A + e.B));\n// after\nvar score = a + b;\n.ExecuteUpdate(s => s.SetProperty(e => e.Config.Score, score));","handlingStrategy":"validation","validationCode":"// Ensure the JSON value selector is a constant, parameter, or JSON property reference.\nvar value = ComputeScore();\nawait ctx.Set<Root>().ExecuteUpdateAsync(s => s.SetProperty(e => e.Config.Score, value));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass only constants, captured variables, or JSON property references as JSON value selectors.","Compute derived values in C# before ExecuteUpdate.","Avoid arithmetic and function calls in JSON value selectors."],"tags":["efcore","executeupdate","owned-json","query-translation"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}