开发者

Switching from xVal to nHibernate Validation

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.ErrorIn开发者_如何学Gofo).


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜