Update fields in DB table by condition without loading

c# entity-framework entity-framework-core linq

Question

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);
1
1
8/26/2018 12:19:42 AM

Accepted Answer

The best solution a have found so far is EntityFramework-Plus https://github.com/zzzprojects/EntityFramework-Plus

As @Smit points out it can be implemented in EFCore in the future. The progress can be tracked here https://github.com/aspnet/EntityFramework/issues/795

-1
12/15/2016 8:02:11 AM

Popular Answer

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


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