Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update fields in DB table by condition without loading

Is it possible to perform simple SQL UPDATE operator with EF Core and LINQ? I want to use LINQ because of type and refactoring safety. And I need to avoid loading bulk of objects back and forth between an app and databse driver Basically I need smth like this:

DB.Items.Update(i => i.Value = 5).Where(i => i.Flag > 5);
like image 695
Roman Kolesnikov Avatar asked May 12 '26 04:05

Roman Kolesnikov


1 Answers

You can use lightweight EFBulk nuget package.

Example code:

var count = db.Items.Where(s => s.Title == "Game")
        .Update(o => new Item { Price = 999, Title = "Tablet" }, db);
like image 59
Circuit Breaker Avatar answered May 13 '26 19:05

Circuit Breaker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!