I played around with nhibernate validator and got a nearly perfect solution.
I can define a property to be validated and it’s done on pre-save. But I have some cases where it’s not working.
Let’s assume I have an object called person and via nhibernate I mapped the address(also an object) to be a property of person (in fact it’s a list of addresses).
When I save the person my address is not validated.
The form to enter the information is made out of partial forms. Would be nice if the address validation could be added to the person’s validation list, but thats not required.
I need a general solution, I cannot validate by “hand” e.g. if person then validate address… Somehow the validator should see that there is an object behind the property which I also have to validate.
Update: What I am looking for is a way to validate mapped objects (hasmany).
After switching to the newest release of nhibernate validator the validation works for subclasses and mapped classes. Together with xVal 1.0 it’s a very satisfying solution.
Now I can define on every property against what it should be validated (e.g. for a regex, length etc…) and I get the message on client side via xVal, on server side via nHibernate Validator. In fact they share the validation pattern and the error messages.
I would recommend this for any nHibernate-Project where a simple definition for validation and messaging is required.