开发者

ObjectContext tracking changes in Entity Framwwork

I need to know if in my objectContext any changes have been made (include attached and detached entities). Should I loop over all my entities in all my O开发者_如何学GobjectSets and check their EntityState or is there a shorter way?


Detached entities are detached = context doesn't know about them and it cannot track its changes. You cannot loop through your ObjectSets - it would load whole your database to your application! If you want to know state of your entities tracked by the context use:

var entries = context.ObjectStateManager.GetObjectStateEntries(~EntityState.Detached);

This will get your collection of ObjectStateEntry where each entry represents single tracked entity or independent association.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜