从 xVal 切换到 nHibernate 验证

发布于 2024-08-09 20:33:51 字数 635 浏览 6 评论 0原文

我有一个带有 xVal 和数据注释的 ASP.NET MVC 项目,我需要切换到 nHibernate 验证。对于数据注释,我有一个 DataAnnotationsValidationRunner,我正在做这样的事情:

  var errors = DataAnnotationsValidationRunner.GetErrors(this).ToList();
  if (errors.Any())
      throw new RulesException(errors);

How do you do that with nHibernate.Validator?

更新:我看到了这样的东西:

 var engine = new ValidatorEngine();
 var errors = engine.Validate(objstovalid)

但我不能这样做,

if (errors.Any())
    throw new RulesException(errors);

因为错误的类型不正确(xVal.ServerSide.ErrorInfo)。

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慵挽 2024-08-16 20:33:51

据我所知,xVal 曾经为 NHibernate Validation 提供运行器,但它只适用于以前的版本。据我所知,当前 NHV 版本没有可用的运行程序。

只是澄清一下,您还想使用 xVal 吗?如果没有,则忽略上述内容,并在 NHV 上运行验证,如下所示:

var validator = new ValidatorEngine();
InvalidValue[] values = validator.Validate(theEntityYouWantToValidate);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文