KEMBAR78
InvalidOperationException when calling ExecuteUpdate with owned entity & using current value · Issue #30528 · dotnet/efcore · GitHub
Skip to content

InvalidOperationException when calling ExecuteUpdate with owned entity & using current value #30528

@mgrosperrin

Description

@mgrosperrin

When calling ExecuteUpdate to conditionnaly update an entity with owned subentity, an System.InvalidOperationException is thrown.

Repro code here: https://github.com/mgrosperrin/repro_issues/tree/efcore-executeupdate-owned-entity
My goal is to update the property only if the user provide a value and to use the current value otherwise (to response to a PATCH API call).

The code in the repo use the null coalescing operator, but I have the same exception with the following code:
updates.SetProperty(e => e.Name, e => e.Name)

Include stack traces

Include the full exception message and stack trace for any exception you encounter.

Use triple-tick fences for stack traces. For example:

System.InvalidOperationException: 'The LINQ expression 'DbSet<Entity>()
    .Select(e => IncludeExpression(
        EntityExpression:
        e, 
        NavigationExpression:
        EF.Property<SubEntity>(e, "Owned"), Owned)
    )
    .ExecuteUpdate(updates => updates.SetProperty<string>(
        propertyExpression: e => e.Name, 
        valueExpression: e => __newName_0 ?? e.Name).SetProperty<string>(
        propertyExpression: e => e.DisplayName, 
        valueExpression: e => __newDisplayName_1 ?? e.DisplayName))' could not be translated. Additional information: The following 'SetProperty' failed to translate: 'SetProperty(e => e.DisplayName, e => __newDisplayName_1 ?? e.DisplayName)'.  See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.'

Include provider and version information

EF Core version: 7.0.4
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 7.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.5.2

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions