Hi,
I have a BusinessObject called Scale having multiple properties of type Weight (e.g. ReferenceWeight, DisplayWeight, StandardWeight, etc.)
The Weight BusinessObject itself has a WeightUnit and a WeightValue.
Now I want to Create a BusinessRule calculating a DisplayWeight when the WeightUnit or the WeightValue of the ReferenceWeight is updated. The DisplayWeight shhould only be updated when a property of the ReferenceWeight has been changed. If the properties of other Weight properties are changed the rules needs not to be called (must not be called).
I tried to mark the Weight BusinessObject as child and call the rule in OnChildChange:
protected override void OnChildChanged(Csla.Core.ChildChangedEventArgs e)
{
base.OnChildChanged(e);
BusinessRules.CheckRules(DisplayWeightProperty);
}
But in this case the rules is executed each time when one of the weight property has been changed. Moreover because I'm changing the DisplayWeight (whichis a Wight itself) the rules is called recursively...
What is the best way to implement a Business rule which depends on the property of a property (a subproperty)?
Thanks
Kirby
Check the parameter e, you should be able to see which property changed.
Hi,
in "Csla.Core.ChildChangedEventArgs e" I can see the name of tha parameter changed (on the child object). I my case I see that WeightUnit or WeightValue was changed but I do not know whether it was a WeightValue of DisplayWeight or ReferenceWeight! If can check the ChildObject on e but that also gives me just an Weight and I have no idea what kind of weight.
Any ideas?
Kirby
Some investigations later...
e.ChildObject and the my ReferenceWeight are the same objects when a property on ReferenceWeight changes... So a simple reference comparison does the trick!
protected override void OnChildChanged(Csla.Core.ChildChangedEventArgs e)
{
base.OnChildChanged(e);
if (e.ChildObject == this.CurrentScaleWeight &&
(e.PropertyChangedArgs.PropertyName == "Unit" || e.PropertyChangedArgs.PropertyName == "Value")
)
{
BusinessRules.CheckRules(CurrentScaleWeightProperty);
}
}
Andy - you were right with your answer of corse!
Cheers
Kirby
I need to do a similar thing except my child property is a list.
In this case, PropertyChangedArgs is null in the ChildChangedEventArgs param. How can I easily find the property that matches the ChildObject that has changed?
Note that I am implementing this in my own BusinessBase class derived from Csla.BusinessBase. So I can't simply do something like e.ChildObject == this.CurrentScaleWeight, like this example.
Any suggestions would be greatly appreciated.
Copyright (c) Marimer LLC