dotnet / dotnet/efcore

Query: Allow use of navigations in ExecuteUpdate set values

Open
#28,627 11 comments 3 reactions 0 assignees View on GitHub
area-bulkupdate customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

```C#
context.Customers.ExecuteUpdate(s => s.SetProperty(c => c.Property, c => c.Navigation.Value));
```
Nav expansion needs to expand `c.Navigation` but it is inside doubly nested lambda hence it doesn't recognize implicitly and requires relational to influence. Scoped out of 7.0 release.
Work-around is to expand navigations in advance.
```C#
context.Customers.Select(c => new { c, c.Navigation }).ExecuteUpdate(s => s.SetProperty(c => c.c.Property, c => c.Navigation.Value));
// or
context.Customers.Select(c => new { c, FirstOrder = c.Orders.OrderBy(o => o.OrderID).FirstOrDefault() })
.ExecuteUpdate(s => s.SetProperty(c => c.c.Property, c => c.FirstOrder.Date));
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.