Entity Framework Core(7) bulk update

c# entity-framework-core

Question

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.

1
8
10/13/2019 10:06:21 PM

Accepted Answer

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

Wiki: Entity Framework Batch Update

9
8/22/2018 10:13:42 PM

Popular Answer

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



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow