I have an ASP.NET MVC project with xVal and data annotations and I need to switch to nHibernate Validation. With data annotations I had a DataAnnotationsValidationRunner
and I was doing something like this:
var errors = DataAnnotationsValidationRunner.GetErrors(this).ToList();
if (errors.Any())
throw new RulesException(errors);
How do you do that with nHibernate.Validator?
Update: I saw something like this :
var engine = new ValidatorEngine();
var errors = engine.Validate(objstovalid)
but I cannot do
if (errors.Any())
throw new RulesException(errors);
because errors is not of the correct type (xVal.ServerSide.ErrorInfo
).
As far as I know xVal used to provice a runner for NHibernate Validation, but it only worked on a previous version. To my knowledge there is no runner available for the current NHV version.
Just to clarify, do you still want to use xVal? If not then ignore the above, and run the validation on NHV like this:
var validator = new ValidatorEngine();
InvalidValue[] values = validator.Validate(theEntityYouWantToValidate);