数据注释或应用程序验证块

发布于 2024-09-15 18:24:27 字数 37 浏览 6 评论 0原文

DataAnnotations 和应用程序验证块有什么区别?

Whats the difference between DataAnnotations and Application Validation Block?

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

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

发布评论

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

评论(1

迷路的信 2024-09-22 18:24:27

DataAnnotations 是一个基于属性的模型,用于“注释”数据,它位于 .NET 框架本身中。它最明显的用途是验证,例如 ASP.NET MVC 所做的那样。 Validation Application Block 本身是一个验证框架,由 Microsoft P&P 团队创建,但它不是 .NET 框架的一部分。它还包含用于“注释”数据的属性,在最新版本 (5.0) 中,这些属性继承自 DataAnnotations,使其在某种程度上可以与 DataAnnotations 互换。

验证应用程序块,或者实际上整个企业库,更专注于企业开发。 VAB 允许许多更复杂的场景。例如,它允许您将验证规则放入配置文件中,或者(需要一些工作)放入代码中。它还允许称为“规则集”的功能,允许对验证进行分组并仅触发对象上的一组规则。对于 VAB 验证而言,没有什么是你不能做的,但这当然是有代价的。代价是复杂性。虽然设计得当,但 VAB 并不容易学习,因为我仍在学习使用它做事的新方法。

与DataAnnotations相比,DataAnnotations非常简单,但在涉及更复杂的场景时也非常有限。

DataAnnotations is an attribute based model to 'annotate' your data and it is in the .NET framework itself. Its most obvious use is for validation, as ASP.NET MVC does for instance. Validation Application Block itself is a validation framework, created by the Microsoft P&P team, but it is not part of the .NET framework. It also contains attributes to 'annotate' your data and in its newest version (5.0) the attributes inherit from DataAnnotations, making it interchangeable with DataAnnotations to some extent.

Validation Application Block, or the whole Enterprise Library actually, is more focused on enterprise development. VAB allows many more complex scenarios. For instance it allows you to put the validation rules in configuration files, or (with a bit of work) in code. It also allows a feature called 'rulesets', allowing to group validations and trigger only a single group of rules on an object. There isn’t much you cannot do what validation is concerned with VAB, but this of course comes at a price. The price is complexity. While designed properly, VAB is not easy to learn as I’m still learning new ways to do things with it.

Compared to DataAnnotations, DataAnnotations is very easy, but also very limited when it comes to more complex scenarios.

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