Is it possible to see if a specific property changed on a modified entity?

荒凉一梦 提交于 2019-12-13 19:31:16

问题


When saving a certain entity I want to send a notification email if the Approved property of this entity has changed.

            if (changedEntity.Entity is Option)
            {
                // Pseudo
                if changedEntity.Entity.Approved changed {
                     send notification()
                }
            }

Is there a certain way to do this? Or can it be done by comparing the CurrentValues against the OriginalValues?


回答1:


If you know the specific entity that you want to 'watch', you can use the EntityAspect.propertyChanged event (see: http://breeze.github.io/doc-js/api-docs/classes/EntityAspect.html#event_propertyChanged) like this:

// assume order is an order entity attached to an EntityManager.
myEntity.entityAspect.propertyChanged.subscribe(function(propertyChangedArgs) {
    // this code will be executed anytime a property value changes on the 'myEntity' entity.
   if ( propertyChangedArgs.propertyName === "Approved") {
      // perform your logic here.
   }
});

Or if you want to watch a specific property on every entity, you can perform a similar test using the EntityManger.entityChanged event (see: http://breeze.github.io/doc-js/api-docs/classes/EntityManager.html#event_entityChanged)

  myEntityManager.entityChanged.subscribe(function (args) {
    // entity will be the entity that was just changed;
    var entity = args.entity;
    // entityAction will be the type of change that occured.
    var entityAction = args.entityAction;
    if (entityAction == breeze.EntityAction.PropertyChange) {
       var propChangArgs = args.args;
       if (propChangeArgs.propertyName === "Approved") {
          // perform your logic here  
       }
    }

  });

More detail can be found here: http://breeze.github.io/doc-js/lap-changetracking.html




回答2:


Use the myEntity.entityAspect.originalValues. This hash will only have values for the changed properties.



来源:https://stackoverflow.com/questions/30594619/is-it-possible-to-see-if-a-specific-property-changed-on-a-modified-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!