Parent validation based on child collection

Jul 25, 2013 at 4:45 PM
Edited Jul 26, 2013 at 8:55 AM

I have a Parent class with a property of type List<Child>. I have set rules for Child class. Now when any of child is invalid I want to set Parent as invalid as well.

How can I write such rule for collection?
Aug 5, 2013 at 4:04 PM

This isn't something that FluentValidation supports. FluentValidation associates error messages against properties, so if a property in one of the children has caused validation to fail, then this will be added to the errors collection and associated with the property, but not with the parent. The parent and child are completely separate for the purposes of validation.

Aug 6, 2013 at 12:29 PM
Thank for your reply.

You comment makes sense.

As work around I extended PropertyValidator to create custom class with logic to verify child list and used same with SetValidator for child collection.