是否有可能,看是否有特定的属性上修改实体变化?(Is it possible to see if a

2019-10-23 06:32发布

当保存一定的实体我想,如果发送电子邮件通知Approved该实体的属性发生变化。

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

是否有某种方式来做到这一点? 或者,可以将它通过比较来完成CurrentValuesOriginalValues

Answer 1:

如果你知道你要“看”的具体的实体,您可以使用EntityAspect.propertyChanged事件(见: http://breeze.github.io/doc-js/api-docs/classes/EntityAspect.html#event_propertyChanged ) 像这样:

// 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.
   }
});

或者,如果你想观看每一个实体的特定属性,你就可以使用EntityManger.entityChanged事件类似的测试(参见: 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  
       }
    }

  });

更多细节可以在这里找到: http://breeze.github.io/doc-js/lap-changetracking.html



Answer 2:

使用myEntity.entityAspect.originalValues 。 该散列将只对更改的属性值。



文章来源: Is it possible to see if a specific property changed on a modified entity?