Business rules questions

Business rules questions

Old forum URL:

griff posted on Wednesday, November 14, 2012

Just started using business rules(and I can see the great power they have) and need some clarification on best practices.

1) Views on when to use a read-only  property or business rule to derive a readonly (non-db) property e.g.  Fullname.

2) I have some complicated calculations e.g. calculation charges on a timesheet.

Should my rules be quite specific or more general?

For instance TotalTravelTime is made up of TotalTravelTimeOutward and TotalTravelTimeReturning. 

TotalTravelTimeOutward is the result of TimeStartToVenue-TimeArriveToVenue and TotalTravelTimeReturning s the result of TimeStartBackFromVenue-TimeEndBackFromVenue.  (there are other rules/calc to calculate charges etc).

So should I have 1 business rule to calculate TotalTravelTime - if I change any one of the four properties that affect the grand total


So should I have 2 business rules to calculate TotalTravelTime - depending on whether outward or return journey.

[I would also have to calculate TotalTravelTimeCharge and other calcs] - so several business rules which are fired when specific properties are changed or one big one that recalculates everything when any one of the properties change.

3) My TotalTravelTimeOutward  is updated via a business rule and not stored in database (as above) - however when I load my page/screen the value is not populated - do I need to call business rule explicitly to get this value?




JonnyBee replied on Wednesday, November 14, 2012

I'd like to clarify the requirements for the RuleEngine:

My preferred solution:

  1. Create ManagedProperties for all values
  2. Create BusinessRules that have just the actual required input properties for each calculated field. 
    (similar to how you would define calculations in a spreadsheet)
  3. Use the advanced setting CascadeOnDirtyProperties to cascade rule checks. Read more here on my blog: 
    The effect is - rerun rules with cascade so long as the property value is updated from context.AddOutValue.
  4. Use CanRunAsAffectedProperty/CanRunOnServer/CanRunInCheckRules to limit when a rule is allowed to run
    (when all is flase => only when user edits the property value - not as result of another property was an affected property).
    In you case maybe set CanRunOnServer/CanRunInCheckRules = false => only when a property is changed on the client.
  5. I do prefer to set the proper values (even into into non-db fields) in the Create/Fetch method
    (or else the object will get dirty when you call BusinessRules.CheckRules() to run calculations)
    You may call BusinessRules.CheckRules() but should expect the object to be Dirty afterwards as result of calculations.

The CascadeOnDirtyProperties is new in Csla 4.5.10 and must be set in DataPortal_Fetch/DataPortal_Create.
IE: It is an instance flag, <bo>.BusinessRules.CascadeOnDirtyProperties, default is false.

griff replied on Wednesday, November 14, 2012

Thank for prompt reply - I will digest and get back

Copyright (c) Marimer LLC