Reputation: 924
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
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