dotnet/efcore · error · InvalidOperationException

The following lambda argument to 'SetProperty' does not repr

Error message

The following lambda argument to 'SetProperty' does not represent a valid value: '{valueExpression}'.

What it means

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.

Source

Thrown at src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.ExecuteUpdate.cs:749

                if (jsonQuery.Path is [])
                {
                    translatedSetters.Add(new ColumnValueSetter(jsonColumn, serializedValue));
                }
                else
                {
                    GenerateJsonPartialUpdateSetterWrapper(jsonQuery, jsonColumn, serializedValue);
                }
            }

            SqlExpression TranslateScalarSetterValueSelector(
                ShapedQueryExpression source,
                Expression valueSelector,
                Type type,
                RelationalTypeMapping typeMapping)
                => TranslateSetterValueSelector(source, valueSelector, type) is SqlExpression translatedSelector
                    // Apply the type mapping of the column (translated from the property selector above) to the value
                    ? _sqlExpressionFactory.ApplyTypeMapping(translatedSelector, typeMapping)
                    : throw new InvalidOperationException(RelationalStrings.InvalidValueInSetProperty(valueSelector.Print()));

            Expression TranslateSetterValueSelector(
                ShapedQueryExpression source,
                Expression valueSelector,
                Type propertyType)
            {
                var remappedValueSelector = valueSelector is LambdaExpression lambdaExpression
                    ? RemapLambdaBody(source, lambdaExpression)
                    : valueSelector;

                if (remappedValueSelector.Type != propertyType)
                {
                    remappedValueSelector = Expression.Convert(remappedValueSelector, propertyType);
                }

                var result = _sqlTranslator.TranslateProjection(remappedValueSelector, applyDefaultTypeMapping: false);

                return result is null

View on GitHub (pinned to 3a2006ef56)

Solutions

  1. Evaluate the value in C# before the call and pass a constant/variable (becomes a parameter).
  2. Ensure the value selector references only mapped properties or literal expressions the translator supports.
  3. For conversions, apply them client-side and pass the converted value.

Example fix

// before
.ExecuteUpdate(s => s.SetProperty(e => e.Total, e => ComputeTotal(e)));
// after
foreach (var e in entities) { e.Total = ComputeTotal(e); }
await ctx.SaveChangesAsync();
// or pass a precomputed value
var total = ComputeTotal();
.ExecuteUpdate(s => s.SetProperty(e => e.Total, total));
Defensive patterns

Strategy: validation

Validate before calling

// Evaluate value selectors client-side to ensure they translate to a SqlExpression.
var total = ComputeTotal();
await ctx.Set<Order>().ExecuteUpdateAsync(s => s.SetProperty(e => e.Total, total));

Prevention

When it happens

Trigger: 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.

Common situations: Passing a helper method result, a computed value the translator cannot push down, or a member of an unmapped type as the value.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/7bb257ec3b184902. Report an issue: GitHub.