Hello, I have a doubt about validation rules that modify other property of another object/instance. As the video recommends it would look like this, but modifying another property in the same object: private static bool SetLoanNumber<T>(T target, Csla.Validation.RuleArgs e) where T : LoanSetup My question is: What is the recommended way to modify a property of parent (or another other) object, for which the object in question has a reference (or way to reference it)? I have created an internal method that modifies the property in the parent object, so that it can be called by the child object. Is there a better way to achieve this? It looks like this:
{
using (target.BypassPropertyChecks)
{
target.LoanNumber = target.GenerateNewLoanNumber();
}
return true;
}internal void SetComplianceReviewed(bool value)
{
using (BypassPropertyChecks)
{
ComplianceReviewed = value;
}
}
I think your solution is correct, you need to ask the other object to safely change its property value, and using a method on that object is a fine solution.
In CSLA 4 we've added an interface to BusinessBase that you could use to temporarily suspend rule processing on another object. This really isn't the reason we added that feature, but it might work for this purpose.
You might also consider adding a rule in the "parent" object that is called when the ChildChanged event is raised on the parent object.
BusinessRules.CheckRules(ComplianceReviewedProperty);
Copyright (c) Marimer LLC