0
votes

I use asp.net mvc with the Durandal Template. My question here is related to the use of Breeze which is integrated in Durandal. I need to detect any entity state changes. I found an answer on StackOverflow which discuss about that problem here: How can I detect a change to an entity's EntityState?

The suggested solution works in most cases I mean we can subscribe to the entityChanged

It works when:

  • an existing entity is modified
  • an existing entity modified is cancelled (rejectChanges)
  • an existing entity is saved (saveChanges)
  • an added entity is generated
  • an added entity is cancelled (rejectChanged)

In all the above cases we can catch the event thanks to the suggested solution in the SO post.

But not when we create a new entity and this entity is saved. This time no event is triggered in the entityChanged. I hoped that when clicked on the save button I can catch the entityChanged event of the entity. Whant is strange to me is that before saving the entity is in the Added state and after saving the entity is in the Unchanged state so there is a change state which occurred but not catched.

Does someone can enlighten me?

Thanks.

1

1 Answers

0
votes

entityChanged is only triggered by the change in the value of the entity. When you add a new entity, like you said, it is in added state. When you modify it, is modified. You can subscribe to the entityChanged event to keep track of when changes occur to the entities state, like Ward suggests below.

http://www.breezejs.com/documentation/inside-entity

How can I detect a change to an entity's EntityState?