I just started looking into NHibernate.Validator and love the
integration it has with NHibernate.  I do have a question though.

I see many examples of how to perform validation using NHV on a newly
created entity like so:

Customer customer = new Customer();
...
customer.Phone = "343-343-343"; //INVALID VALUE
customer.Zip = "34334"; //INVALID VALUE

ValidatorEngine validator = new ValidatorEngine();

if (validator.IsValid(customer))
{
  repo.Save(customer);
}


But I can't find an example of performing validation on an entity
retrieved from a repository and then updated.  ex:

Customer customer = repo.Get(1);
...
customer.Phone = "343-343-343"; //INVALID VALUE

foreach (InvalidValue error in validatorEngine.Validate(customer))
{
  // display the errors...
}

from here I can retrieve the validation errors no problem but the
customer entity is now dirty and my unit of work will try to flush/
commit the changes which causes an InvalidStateException.  I don't
want to handle this exception here as it is assumed I've already
realized the entity is invalid and handled the validation errors as
desired.

Now from here I see a couple of options that I don't like:
1. I could swallow all InvalidStateExceptions
2. I could set some global error state when a validation error has
been found by the validation engine and then always check this global
error state before flushing/committing within my UOW.

Am I missing something here?

Any insight would be greatly appreciated. Thanks!

Gary Brunton

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to