3 ms·
For performance, .NoTracking() and not calling .SaveChanges() on every loop already does wonders. I usually call .SaveChanges() when i % 20 == 0
by NicoJuicy 4y ago
For performance, .NoTracking() and not calling .SaveChanges() on every loop already does wonders.
I usually call .SaveChanges() when i % 20 == 0
- magicalhippo 4y agoWe'll need tracking (if I understand correctly, we need previous values). When calling SaveChanges often, how do you handle rollback in case something fails?
- fabian2k 4y agoEither wrap everything into a transaction or just call SaveChangesAsync only once. The exact behaviour depends on the database here, under the hood this uses database transactions.
- NicoJuicy 4y agoYou can use .NoTracking() and an SQL query for bulk changes ( and minor changes). Eg. Updating one column. Works faster than with .Tracking. The SQL script runs in your transaction, so rollback runs as usual. The i%20==0 condition with .SaveChanges() is used with .Tracking(), yes.