Validation Rules that update a property

Validation Rules that update a property

Old forum URL: forums.lhotka.net/forums/t/9714.aspx


Lazaro posted on Thursday, November 04, 2010

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
{
   using (target.BypassPropertyChecks)
   {
     target.LoanNumber = target.GenerateNewLoanNumber();
   }
   return true;
}

 

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:

 

internal void SetComplianceReviewed(bool value)
{
  using (BypassPropertyChecks)
  {
    ComplianceReviewed = value;
  }
}

RockfordLhotka replied on Thursday, November 04, 2010

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.

JonnyBee replied on Sunday, November 07, 2010

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