有通过数据注解的方式来验证一个日期属性是大于或等于另一个日期属性? [英] Is there a way through data annotations to verify that one date property is greater than or equal to another date property?

查看:260
本文介绍了有通过数据注解的方式来验证一个日期属性是大于或等于另一个日期属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个开始日期结束日期我的 SchoolEvents 模型,我想知道是否有任何数据的注解,我可以用它来验证开始日期小于或等于结束日期并在结束日期大于或等于开始日期

I have a StartDate and EndDate on my SchoolEvents Model and I was wondering if there are any data annotations I could use to verify that the StartDate is less than or equal to the EndDate and that the EndDate is greater than or equal to the StartDate?

推荐答案

从我的角度来看,你必须建立一个<一个href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.customvalidationattribute%28v=vs.95%29.aspx\"相对=nofollow>自定义验证属​​性。你可以看一下在<一个href=\"http://stackoverflow.com/questions/2280539/custom-model-validation-of-dependent-properties-using-data-annotations\">link验证遵循特定的验证。这将需要你的努力了这么多。
相反,您使用的数据注解你应该申请流利的验证,这将帮你这么多省力。这是很容易设置,简单的和独立的关注,你不需要视图模型,领域对象和验证依赖于业务规则之间的混合。

From my view point, you have to build a custom validation attribute. You can look at the link to validate follow specific your validation. It will take your efforts so much. Instead of you use data annotation you should apply Fluent Validation which will help you so much reduce effort. It is easy to setup, straight forward and separate of concern, you do not need mixing between view model, domain objects and validations which depends on business rule.

这篇关于有通过数据注解的方式来验证一个日期属性是大于或等于另一个日期属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆