-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
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