Parent validation based on child collection

Jul 25, 2013 at 3:45 PM
Edited Jul 26, 2013 at 7:55 AM
Hi,

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?
Coordinator
Aug 5, 2013 at 3:04 PM
Hi

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.

Jeremy
Aug 6, 2013 at 11:29 AM
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.