I have a rule in my children objects that uses some values from the parent object. The rule must be executed when any of those values in the parent changes. The rule also adds different error result messages depending of certain conditions.
The options I have are:
1-Add the needed properties to the child object and update its values every time the values in the parent change using PropertyHasChanged. Those properties have to be loaded also for every new child and when the children objects are being load from the database.
What I don't like about this approach is to add properties to the child that don't really belong there and all the code needed to load those properties.
2-Create a lambda rule in the child that uses the values from the parent through the Parent property of the child object. Add some method in the child object to call BusinessRules.CheckRules(MyProperty). That method will be used from the parent object inside PropertyHasChanged to trigger the execution of the rule in the children.
In this option I don't know how to output different messages for the rule depending of conditions inside the rule code. This is how I define the rule:
BusinessRules.AddRule<MyChild>(MyPropertyProperty,
o => {
…rule code here using (MyParent)o.Parent…
},“Broken rule message”);
My questions are:
Is there a better solution for this?
If not, how can I output different messages from the rule using the second option?
Thanks in advance.