{"record":{"id":"7bb257ec3b184902","repo":"dotnet/efcore","slug":"the-following-lambda-argument-to-setproperty-doe-7bb257","errorCode":null,"errorMessage":"The following lambda argument to 'SetProperty' does not represent a valid value: '{valueExpression}'.","messagePattern":"The following lambda argument to 'SetProperty' does not represent a valid value: '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.ExecuteUpdate.cs","lineNumber":749,"sourceCode":"                if (jsonQuery.Path is [])\n                {\n                    translatedSetters.Add(new ColumnValueSetter(jsonColumn, serializedValue));\n                }\n                else\n                {\n                    GenerateJsonPartialUpdateSetterWrapper(jsonQuery, jsonColumn, serializedValue);\n                }\n            }\n\n            SqlExpression TranslateScalarSetterValueSelector(\n                ShapedQueryExpression source,\n                Expression valueSelector,\n                Type type,\n                RelationalTypeMapping typeMapping)\n                => TranslateSetterValueSelector(source, valueSelector, type) is SqlExpression translatedSelector\n                    // Apply the type mapping of the column (translated from the property selector above) to the value\n                    ? _sqlExpressionFactory.ApplyTypeMapping(translatedSelector, typeMapping)\n                    : throw new InvalidOperationException(RelationalStrings.InvalidValueInSetProperty(valueSelector.Print()));\n\n            Expression TranslateSetterValueSelector(\n                ShapedQueryExpression source,\n                Expression valueSelector,\n                Type propertyType)\n            {\n                var remappedValueSelector = valueSelector is LambdaExpression lambdaExpression\n                    ? RemapLambdaBody(source, lambdaExpression)\n                    : valueSelector;\n\n                if (remappedValueSelector.Type != propertyType)\n                {\n                    remappedValueSelector = Expression.Convert(remappedValueSelector, propertyType);\n                }\n\n                var result = _sqlTranslator.TranslateProjection(remappedValueSelector, applyDefaultTypeMapping: false);\n\n                return result is null","sourceCodeStart":731,"sourceCodeEnd":767,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.ExecuteUpdate.cs#L731-L767","documentation":"Thrown by TranslateScalarSetterValueSelector when the value selector does not translate to a SqlExpression. After remapping the lambda and applying the column's type mapping, if the result is not a SqlExpression the value is reported as invalid for SetProperty.","triggerScenarios":"SetProperty with a value selector that the SQL translator cannot render as a scalar SQL expression — e.g. a method call, an unmapped member, or a complex expression in the value position. Distinct from the property-selector error: this is specifically about the VALUE side.","commonSituations":"Passing a helper method result, a computed value the translator cannot push down, or a member of an unmapped type as the value.","solutions":["Evaluate the value in C# before the call and pass a constant/variable (becomes a parameter).","Ensure the value selector references only mapped properties or literal expressions the translator supports.","For conversions, apply them client-side and pass the converted value."],"exampleFix":"// before\n.ExecuteUpdate(s => s.SetProperty(e => e.Total, e => ComputeTotal(e)));\n// after\nforeach (var e in entities) { e.Total = ComputeTotal(e); }\nawait ctx.SaveChangesAsync();\n// or pass a precomputed value\nvar total = ComputeTotal();\n.ExecuteUpdate(s => s.SetProperty(e => e.Total, total));","handlingStrategy":"validation","validationCode":"// Evaluate value selectors client-side to ensure they translate to a SqlExpression.\nvar total = ComputeTotal();\nawait ctx.Set<Order>().ExecuteUpdateAsync(s => s.SetProperty(e => e.Total, total));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass constants or parameters as SetProperty values, not method calls.","Keep value selectors as direct member references or literals.","Precompute non-translatable expressions."],"tags":["efcore","executeupdate","setproperty","query-translation"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}