Reputation: 67345
Can anyone guess why the developers of Entity Framework didn't include UPDATE
and DELETE
semantics?
I have a list of integer IDs. And I need to update all corresponding rows. Without going back to raw SQL or a stored procedure, the best I can do is load each and every matching row and update the object and then save it.
This takes way too long. Is there some cool way to handle this in the latest versions of Entity Framework that would be more efficient?
Upvotes: 0
Views: 59
Reputation: 17111
The open source "Entity Framework Extended Library" seeks to perform batch updates etc.
Here is an example from their github page:
//update all tasks with status of 1 to status of 2
context.Tasks.Update(
t => t.StatusId == 1,
t2 => new Task {StatusId = 2});
//example of using an IQueryable as the filter for the update
var users = context.Users.Where(u => u.FirstName == "firstname");
context.Users.Update(users, u => new User {FirstName = "newfirstname"});
Upvotes: 1