{"record":{"id":"35013c61d4c4d155","repo":"dotnet/efcore","slug":"invalidpropertyinsetproperty","errorCode":"InvalidPropertyInSetProperty","errorMessage":"The following lambda argument to 'SetProperty' does not represent a valid property to be set: '{propertyExpression}'.","messagePattern":"The following lambda argument to 'SetProperty' does not represent a valid property to be set: '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.ExecuteUpdate.cs","lineNumber":86,"sourceCode":"            // WHERE Id IN (SELECT ...) syntax), since we allow projecting out to arbitrary shapes (e.g. anonymous types) before the\n            // ExecuteUpdate.\n\n            // To rewrite the query, we need to know the primary key properties, which requires getting the entity type.\n            // Although there may be several entity types involved, we've already verified that they all map to the same table.\n            // Since we don't support table sharing of multiple entity types with different keys, simply get the entity type and key from\n            // the first property selector.\n\n            // The following mechanism for extracting the entity type from property selectors only supports simple member access,\n            // EF.Function, etc. We also unwrap casts to interface/base class (#29618). Note that owned IncludeExpressions have already\n            // been pruned from the source before remapping the lambda (#28727).\n            var firstPropertySelector = setters[0].PropertySelector;\n            if (!IsMemberAccess(\n                    RemapLambdaBody(source, firstPropertySelector).UnwrapTypeConversion(out _),\n                    RelationalDependencies.Model,\n                    out var baseExpression)\n                || _sqlTranslator.TranslateProjection(baseExpression) is not StructuralTypeShaperExpression shaper)\n            {\n                throw new InvalidOperationException(RelationalStrings.InvalidPropertyInSetProperty(firstPropertySelector));\n            }\n\n            // TODO: #36336\n            if (shaper.StructuralType is not IEntityType entityType)\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.ExecuteUpdateSubqueryNotSupportedOverComplexTypes(shaper.StructuralType.DisplayName()));\n            }\n\n            if (entityType.FindPrimaryKey() is not { } pk)\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.ExecuteOperationOnKeylessEntityTypeWithUnsupportedOperator(\n                        nameof(EntityFrameworkQueryableExtensions.ExecuteUpdate),\n                        entityType.DisplayName()));\n            }\n\n            // Generate the INNER JOIN around the original query, on the PK properties.","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.ExecuteUpdate.cs#L68-L104","documentation":"Thrown on the ExecuteUpdate pushdown path (PushdownWithPkInnerJoinPredicate, used when the provider cannot natively translate the update) when the first SetProperty lambda's property selector is not a recognizable member access binding to an entity shaper. The pushdown rewrite needs to locate the entity and its primary key from the property selector; if the lambda does not represent a valid property, the rewrite fails.","triggerScenarios":"Calling ExecuteUpdate where SetProperty receives a lambda that is not simple entity member access - e.g. SetProperty((c => 5), ...), SetProperty(c => c.CalculatedField, ...) where CalculatedField is not a mapped property, or a lambda referencing a projection/anonymous member instead of the entity parameter.","commonSituations":"Trying to set a computed/non-mapped field; passing a constant or expression instead of a property selector; composing SetProperty over a Select that changed the parameter type; typos in member names.","solutions":["Use a simple member-access lambda over the entity parameter: SetProperty(e => e.Name, value) where Name is a mapped scalar property.","Ensure the property referenced is a mapped IProperty on the target entity (not a computed/unmapped field).","Avoid projecting to anonymous types before ExecuteUpdate; operate on the entity DbSet directly.","If setting a value derived from another column, reference the entity property and compute the value in the value selector, not the property selector."],"exampleFix":"// before\nawait db.Blogs.Where(b => b.Id == id)\n    .ExecuteUpdateAsync(s => s.SetProperty(b => 5, b => b.Rating));\n// after - property selector must be a mapped property of the entity\nawait db.Blogs.Where(b => b.Id == id)\n    .ExecuteUpdateAsync(s => s.SetProperty(b => b.Rating, b => 5));","handlingStrategy":"validation","validationCode":"static bool IsValidSetPropertySelector(LambdaExpression selector, IEntityType et)\n    => selector.Body is MemberExpression me\n       && me.Expression == selector.Parameters[0]\n       && et.FindProperty(me.Member.Name) is not null;\n\nvar selector = (LambdaExpression)setters[0].PropertySelector;\nif (!IsValidSetPropertySelector(selector, entityType))\n    throw new InvalidOperationException(\"SetProperty selector must be a simple mapped property of the entity.\");","typeGuard":"static bool IsEntityMemberAccess<T>(Expression<Func<T, object?>> selector)\n    => selector.Body is MemberExpression { Expression: ParameterExpression };\n\n// usage guard before ExecuteUpdate\nif (!IsEntityMemberAccess((Expression<Func<Blog, object?>>)(b => b.Name))) throw new ArgumentException(\"bad selector\");","tryCatchPattern":null,"preventionTips":["Always use simple entity-parameter member access in SetProperty selectors.","Reference only mapped scalar IProperty names in SetProperty.","Avoid anonymous/projection selectors before ExecuteUpdate.","Put computed logic in the value selector, not the property selector."],"tags":["executeupdate","setproperty","lambda","bulk-operations"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}