Last post Sep 07, 2016 05:38 AM by Nan Yu
Sep 06, 2016 12:05 PM|sudip_inn|LINK
i have just started EF. so please tell me what is change tracking concept is there.
what extra i need to do to use EF change tracking feature ?
how it works. please discuss with small code just to explain how people benefited from this feature.
Sep 06, 2016 09:17 PM|deepalgorithm|LINK
Entity Framework is able to track the changes made to entities and their relationships so the correct updates are made on the database when the SaveChanges method of DbContext is called. Internally it keeps two sets of values. One for the original
set and one for the updated set.
Behind the scenes - Entity Framework will compare current and original values and build the correct SQL update statement for to modify changed values in the database.
So the benefit of this feature is so that when you call SaveChanges, it will know what entities to update in database and more specifically, what SQL to generate and run against the database.
Change tracking is enabled by default. We can disable change tracking by setting the AutoDetectChangesEnabled property of DbContext to false. If this property is set to true then the Entity Framework maintains the state of entities.
You disable change tracking by setting the AutoDetectChangesEnabled property of DbContext to false. See the following:
Here is an example of using this feature:
Sep 07, 2016 05:38 AM|Nan Yu|LINK
Hi sudip_inn ,
Please refer to this explanation :
When you load the entity from the context it keeps additional data structure - let's call it entry. The entry contains two set of values - original values and current values. When you execute the SaveChanges operation EF goes through your customer entity
and updates current values in the entry so that they match with the real state of your entity , this operation is called detecting changes. During SQL command generation EF will compare current and original values and build SQL update statement for to modify
changed values in the database.
The Change Tracking tracks changes while adding new record(s) to the entity collection, modifying or removing existing entities.These track changes are lost if they are not saved before the DbContext object is destroyed. Also ,To track any entity by the
context, it must have the primary key property.