Search code examples
wpfentity-frameworkself-tracking-entitieschange-trackingobject-state

Getting the real State of SelfTracking Entities, including Navigation Properties


I would like to change the display of objects if they have unsaved changes. I thought I could just use ChangeTracker.State, but that doesn't change to Modified if I change a Navigation Property.

For example, a Contact object contains Navigation Properties for Phones, Addresses, and Emails. If I change the Contact's Name, the state will change to Modified but changing a Phone leaves the object's state Unchanged.


Solution

  • State associated with a single entity doesn't reflect state of the object graph. How do you expect it should work? It would result in setting all entities to modified once anything in the graph changes because everything is somehow related to each other.

    You can subscribe ObjectStateChanging events of your change trackers and be notified about changes in the graph.