efcore
efcore copied to clipboard
Query: Allow use of navigations in ExecuteUpdate set values
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.
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));