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.
精彩评论