BusinessRule - How to get context.Target to have the current values

BusinessRule - How to get context.Target to have the current values

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


joseph99 posted on Thursday, June 12, 2014

I am trying to create a business rule that needs the current value of two other fields in the target object.  The target object always has the previous values when the rule executes.  Is there a working example of how to implement a business rule that interacts with the business object.

Thanks.

Joe

JonnyBee replied on Friday, June 13, 2014

Hi,

The target object is always the "current" object and the current values but it may be that the rule is executed before values have been updated by another rule?

Can you provide us with a small sample solution?

joseph99 replied on Friday, June 13, 2014

Thank you for getting back to me.  I figured it out. I needed to set up the Dependencies so that all of the validations would fire.  However, I do have another question.  Does the

BusinessRules.AddRule(

 

new Dependency(ClientIsHomeLessProperty, StateIdProperty));

BusinessRules.AddRule(

 

new Dependency(OutOfStateZipProperty, StateIdProperty));

over ride the

BusinessRules.ProcessThroughPriority = 2; ?

My State Rule

BusinessRules.AddRule(

 

new RuleStateIdValid(StateIdProperty) { Priority = 0 });

When the State Id validation fails, Id does not exist.  The

BusinessRules.AddRule(

 

new RuleOutOfStateZipValidStates(OutOfStateZipProperty) { Priority = 3 });

still executes.

Thanks.

Joe

JonnyBee replied on Friday, June 13, 2014

Hi,

You probably have misunderstood how the Priority property is used.

Rules is always executed on a Per-Property basis and Priority is only ever used to set the order of execution within the same PrimaryProperty.

joseph99 replied on Friday, June 13, 2014

Then I must have misread page 86 in the "CSLA 4: Creating Business Objects".

Short-Circuiting Rules

In this example I’ve changed the value to 5, so in instances of this particular business class rules at priority 5 or less will always execute, and those at priority 6 and higher will only run if no validation rule has failed.

Thanks.

Joe

Copyright (c) Marimer LLC