Multiple Property Rules - CSLA 4.2

Multiple Property Rules - CSLA 4.2

Old forum URL:

bwebber posted on Monday, October 24, 2011

I have a rule that is applied to 2 properties - either 1 or the other is required, but not both.

I understand that when one adds properties to the AffectedProperties of a rule, the rules for those affected properties will be fired after the rule executes.

My problem is that I have a single rule, that needs to be checked if either property is changed, and the rule must only be broken once, but it breaks twice (once for each property).

I add my rules as follows:


BusinessRules.AddRule(New AtLeastOneValueSpecifiedRule(EntityIDProperty, IndividualIDProperty))

BusinessRules.AddRule(New AtLeastOneValueSpecifiedRule(IndividualIDProperty, EntityIDProperty))

The rule itself adds the 2nd property to its AffectedProperties.  This works well (showing errors on the correct fields) and the rule is broken/unbroken correctly.

The problem is my UI scans the object graph and displays an Error Tree based on the broken rules and because there are effectively 2 rules in place I get the following in my error tree when this rule is broken:

> Entity or Individual is required

> Individual or Entity is required

Is there a way around this using CSLA or should I build a workaround into my UI error tree functionality?


JonnyBee replied on Monday, October 24, 2011

So, you want the UI to display the error message on both fields but only have one entry in the ErrorTree?

One option could be to set the severity of the second property to Warning - then you could filter out Warning/Information level from the ErrorTree.

The second option is to only set the broken rule on one of the fields.

If you want the error message to appear on both fields then by design - you must have 2 entries in broken rules collection.

bwebber replied on Monday, October 24, 2011

Thanks for the quick reply Smile

Yes, that's exactly what I want, I do not want to lose the errors on both fields.  I already use the error tree for warnings and info.  It would be awesome to be able to set multiple Primary properties to support the IDataErrorInfo per property with only a single rule added to the BrokenRulesCollection.

I have modified my rule class to list the property names in alphabetical order when generating a default rule description and modified my error tree code to only add rules that have a unique description.

This is working nicely ;) 

Copyright (c) Marimer LLC