Validation rules in a root editable collection

Validation rules in a root editable collection

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


JonM posted on Thursday, May 10, 2007

Many of my root objects are editable collections.  I need collection wide rules for things like: Requiring unique names across child objects and requiring at least 1 item in the collection.

Can I put validation rules in a Editable Root Collection?

RockfordLhotka replied on Thursday, May 10, 2007

You can, but there's no support from CSLA because there's no support from data binding.

In other words, there's no sanctioned way to display rules from a collection in the UI - data binding simply doesn't have this concept.

Due to that, I didn't implement anything like ValidationRules in BusinessListBase, because the results couldn't be displayed.

But you most certainly can implement checks by overriding Save() and making sure the collection is valid before saving it - probably throwing a ValidationException if it is out of order.

Also, see this thread.

JonM replied on Friday, May 11, 2007

Rocky,

I checked out the thread, using the parent property to check the other entries makes sense to me.  hen I try to use the parent property I get an exception because the parent property hasn't been set. 

Does the CSLA set the parent property automatically or do I need to set it somewhere?

RockfordLhotka replied on Friday, May 11, 2007

BusinessListBase automatically sets the parent property on the child objects it contains.

 

If you have some other parent-child relationship then the property is not automatically set, and you’ll need to implement you own code in the parent to call SetParent() on the child.

 

Rocky

 

Copyright (c) Marimer LLC