Difference between MergeOption.NoTracking, ObjectContext.Detach, SetChangeTracker(Null)
Hi
If anyone could please elaborate the difference between the three, i am new to EF and sometimes MergeOption.NoTracking happens to work whereas sometimes ObjectContext.Detach, but i never get the g开发者_StackOverflow社区ist of it. I would like to know Which situations should i use them. Also, if there is an object graph attached to some entity (either by firing the Include function or by calling EntityReference.Load()) What should be called if 1.) i don't want other objects attached to the entity 2.) i want all objects referenced by the entityAny help would be greatly appreciated.
Regards HirenMergeOption.NoTracking
is used to improver performance for loading entities which will not be modified. Entity is in this case is not tracked by the context but it is still attached and lazy loading works.
ObjectContext.Detach
completely removes entity from object context scope so the entity is not tracked and lazy loading doesn't work.
IEntityWithChangeTracker.SetChangeTracker
is imho more like infrastructure for EntityObject
. It is heavily used inside EF when entities are materialized and attached to the context.
精彩评论