Reputation: 14586
I have a parent entity with navigation property. If any of the children in the collection is modified the child's entityState is set to modified but the parent's entityState remains unchanged.
I need a visual indication on screen to show that some modifications were made to the parent entity, even if the modification was made on a child in the np collection.
I can't use hasChangesChanged because that's too generic. I need to set the visual indicator only when changes were made either on the parent entity itself or one of the entities in the np collection.
Is there an easy way for doing that, or do I have to watch for modifications manually ?
Upvotes: 0
Views: 303
Reputation: 14995
Apparently I didn't hit save on my other answer but the gist of what you are trying to do is track changes to child entities. You do need to 'manually' subscribe to those changes, as there is nothing that I know of out of the box to watch the entire object graph. (keep in mind that could be HUGE and have adverse effects)
The best option that I have used before (pseudo-code, using Knockout but should suffice) -
Initialize the parent with an additional unmapped property -
metadataStore.registerEntityTypeCtor('Person', null, personInitializer);
function personInitializer(person) {
person.hasChanges = ko.computed(function() {
ko.utils.arrayForEach(person.children(), function (child) {
child.entityAspect.propertyChanged.subscribe(function () {
// Do your logic here
});
});
});
}
One thing to remember is you want to keep track of the subscription and be sure to dispose of it when you dispose of the parent object.
Upvotes: 1