Validation of child property

Validation of child property

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


JoshL posted on Tuesday, December 09, 2008

In a business object, I have two mutually exclusive properties with a business rule requiring that one be entered. One is a simple string, the other is a child collection. The custom business rule checks the count of the child collection.

I used ValidationRules.AddDependentProperty to add a dependency between the two properties. However, when I add objects to the collection, no rules are checked.

Is it reasonable to expect that CSLA would check rules created for a child property, or should these be handled manually?

For now, I've overridden OnChildChanged to call ValidationRules.CheckRules if the child object changes.

daniel_higgins replied on Tuesday, December 09, 2008

In the base class the [ property value has changed => check rules ] logic works agains the value of the property. For a property of type MyChildCollection, the value of the property is a reference to the collection. If you set the property to a new collection, I would expect the rule checking to fire for that property. Adding a new child to the collection would not result in a call to the SetProperty logic in the parent object, since you are not altering the property value.

Whether it is 'reasonable to expect that CSLA would check rules' down the object graph, I suppose, might depend on the kind of performance/functionality trade-off appropriate to the specific application.

Copyright (c) Marimer LLC