开发者

ObjectContext tracking changes in Entity Framwwork

开发者 https://www.devze.com 2023-03-21 13:12 出处:网络
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 Entity

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

精彩评论

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