KiRa
KiRa

Reputation: 924

Linq Update vs SQL Update performance

Let say I got a 500 - 1,000 data in my table.

LINQ

(from a in db.Person 
     select a).ToList().ForEach(x => x.PersonName = "Juan");
db.SaveChanges();

SQL

UPDATE dbo.Person
SET PersonName = Juan;

Which query is much better performance in terms of speed when updating a record?.

Upvotes: 0

Views: 124

Answers (1)

LoztInSpace
LoztInSpace

Reputation: 5697

Clearly the raw update will be faster. ToList() materialises the data set (so it gets read). The update may or may not track changes in your entity but by default will. Then it sends it all back again.

The update just operates at the database.

Without the ToList() it might be closer.

Upvotes: 2

Related Questions