开发者

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 entity

Any help would be greatly appreciated.

Regards

Hiren


MergeOption.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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜