Update statement with Entity Framework

entity-framework executenonquery

Question

Simple question, is it possible to achieve this query this with Entity Framework when updating one entity?

update test set value = value + 1 where id = 10
1
7
12/17/2013 2:30:29 AM

Accepted Answer

Not really under this form no.

You will have to select all entities that match your criteria, foreach over them and update them.

If you are looking for something that will do it right in the DB because your set could be huge, you will have to use SQL directly. (I don't remember if EF has a way to execute UPDATE queries directly the way Linq To SQL does).

5
3/16/2009 8:28:12 PM

Popular Answer

Use the Batch Update feature of the Entity Framework Extended Library, like this:

dbContext.Tests.Update(t => t.Id == 10, t => new Test() { Value = t.Value + 1 });


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