ObjectContext tracking changes in Entity Framwork

I need to know if any changes have been made to my context object (including attached and individual objects). Should I iterate over all my objects in all my object sets and check their EntityState or is there a shorter way?

+1
source share
1 answer

Detached objects are disconnected = the context does not know about them and cannot track its changes. You cannot go through your ObjectSets - it will load your entire database into your application! If you want to know the state of your objects that are tracked by context, use:

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

This will lead to your ObjectStateEntry collection, where each record represents a single tracked entity or independent association.

+1
source

Source: https://habr.com/ru/post/1379986/


All Articles