Update records with Entity Framework without first loading

advertisements

I'm looking for a way to write code with Entity Framework to update 1000's of records that match a criteria.

In SQL it would look like this

UPDATE [Items]
SET [IsInSeason] = 1
WHERE [Name] like '%summer%'

It doesn't make sense for me to load in all items into memory just for this update.

And I would like to avoid writing regular SQL statements (if possible)


Out of the box, Entity Framework has no such ability. You either need to load the entities before updating, or you need to resort to raw SQL (as an ad-hoc statement, or by calling a stored procedure).

There are a few EF extension packages, however, that claim to support this batch update and batch delete scenario. I haven't had any personal experience with any of them, but give them a look: