How to bulk update entities using EF Core(7)?
I do not want to load entities from the DB server, modify properties and update. I just want to EF generate appropriate UPDATE statement.
As the accepted answer pointed, Entity Framework Core doesn't support to updates directly in the database yet.
Disclaimer: I'm the owner of the project Entity Framework Plus
However, EF+ already supports Query Batch Update without loading entities in the context (Support: EF Core, EF6, EF5)
// using Z.EntityFramework.Plus; // Don't forget to include this.
// UPDATE all users inactive for 2 years
ctx.Users.Where(x => x.LastLoginDate < DateTime.Now.AddYears(-2))
.Update(x => new User() { IsSoftDeleted = 1 });
At the day I am posting this answer, with the information in my possession, it looks like it is a work in progress
See https://github.com/aspnet/EntityFramework/issues/795
EF does not provide a batch update mechanism. A proposal is below. Context.Customers.Update().Where.( c => c.CustType ==“Newâ€).Set( x => x.CreditLimit=0)
Will you consider this feature? More details here: https://entityframework.codeplex.com/workitem/52