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 c开发者_开发问答hange 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.
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.
Everything is in the ChangeTracker.
You need to look at:
- State
- ObjectsAddedToCollection
- ObjectsRemovedFromCollection
- OriginalValues
You might also want to look at ExtendedProperties if you're generating your model without Foreign Key IDs and you have no repopulation policy in practice when you deserialize the STE.
精彩评论