Complex validation
Old forum URL: forums.lhotka.net/forums/t/6253.aspx
Slayer posted on Monday, January 26, 2009
Hi everyone...
I have a scenario where I have a parent(customer) object, which contains a collection of child(address) objects. When there are more that 5 child objects, my parent object`s state must become invalid. But when I remove a child object, my parent`s state must become valid again.
Is this possible with the CSLA framework ? My experience is somewhat limited.
Thanks in advance...ayubu replied on Monday, January 26, 2009
You can addbusiness rule for the Collection property as normal then inside the validation method you just call
if targe t.Addresses.Count > 5 then
e.Description ="Error message"
return false
else
return true
end if
Slayer replied on Monday, January 26, 2009
Im not sure I understand...My collection property only has a GET.
public Addresses AddrColl
{
get
{
return _addrColl;
}
}
So the validation needs to happen after I call Customer.AddrColl.Remove(addrObj).Fintanv replied on Monday, January 26, 2009
I handle a similar requirement in the following way. My collection is actually a child of a business object. The root object contains 0 or more root level properties, 1 or more editable child collections, and 0 or more read only collections for pick lists. Since the editable collection is a property of the root, the rule to check the valid/invalid count quantity of the collection, exists in the root object.
The root object also overrides the OnChildChanged method, and if the changed child is the collection with the count rule then I run the ValidationRules.CheckRules(property_name) and OnPropertyChanged(property_name).
Regards
-- Fintan
Copyright (c) Marimer LLC