efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Query: Allow use of navigations in ExecuteUpdate set values

Open smitpatel opened this issue 3 years ago • 0 comments

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));

smitpatel avatar Aug 08 '22 20:08 smitpatel