Entity Framework - Change Tracking

Entity Framework provides the ability to track the changes made to entities and their relations, so the correct updates are made on the database when the SaveChanges method of context is called.Entity framework supports automatic change tracking of the loaded entities during the life time of the context. Entity framework will not add any entity in the conceptual model which does not have an EntityKey property.

a) The Change Tracking tracks changes while adding new record(s) to the entity collection, modifying or removing existing entities.
b) All the changes are kept by the DbContext level.
c) Track changes are lost if they are not saved before the DbContext object is destroyed.
d) DbChangeTracker class gives all the information about current entities being tracked by the context.
e) To track any entity by the context, it must have the primary key property.

Change tracking is enabled by default in Entity Framework. Change tracking can also disable 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.

using (var context = new UniContextEntities()) 
     context.Configuration.AutoDetectChangesEnabled = true;

Praesent mattis

Pellentesque viverra vulputate enim. Aliquam erat volutpat. Pellentesque tristique ante ut risus. Quisque dictum. Integer nisl risus, sagittis convallis, rutrum id, elementum congue, nibh. Suspendisse dictum porta lectus. Donec placerat odio vel elit.

Read More