Reputation: 235
Regarding Entity Framework states, specifically when it comes to updating records with a SaveChanges
call, I know it'll only update records that have a modified EntityState
(ignoring add/delete for now)
My question is how is this tracked and how does it handle assignments with unchanged values?
I'm trying to work out if
if (value1.Text != table.value1) { table.value1 = value1.Text; }
is necessary to stop superfluous updates or if I can get away with:
table.value1 = value1.Text;
or will that set the state to a 'modified' flag on the record, even if the value is the same?
Thanks!
Upvotes: 2
Views: 261
Reputation: 163
As in https://msdn.microsoft.com/en-us/data/jj556205,
When using most POCO entities the determination of how an entity has changed (and therefore which updates need to be sent to the database) is handled by the Detect Changes algorithm. Detect Changes works by detecting the differences between the current property values of the entity and the original property values that are stored in a snapshot when the entity was queried or attached.
Entity Framework automatically run the above Detect Changes when calling to DbContext.SaveChanges. And EF actually determine changes by comparing current value and original value to
Upvotes: 2