本文介绍了十进制的最佳数据注释(18,2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在SQL Server 2008中的列类型为Decimal(18,2).但是,在实体框架上,什么可以在asp MVC Web应用程序中应用于此属性的最佳数据注释验证是什么?
I have a column inside my sql server 2008 wih type of Decimal(18,2). But on entity framework what is the best data annotation validation I can apply to this property, inside my asp MVC web application ?
推荐答案小数点没有显式的数据注释,因此您需要使用两个单独的注释来添加约束.
There is no explicit data annotation for a decimal so you need to use two separate ones to add constraints.
[RegularExpression(@"^\d+\.\d{0,2}$")]此正则表达式将确保该属性最多具有两个小数位.
This regular expression will make sure that the property has at most two decimal places.
[Range(0, 9999999999999999.99)]假设您不接受任何负数.否则,将0替换为-9999999999999999.99.
Assuming you aren't accepting any negative numbers. Otherwise, replace 0 with -9999999999999999.99.
[RegularExpression(@"^\d+\.\d{0,2}$")] [Range(0, 9999999999999999.99)] public decimal Property { get; set; }更多推荐
十进制的最佳数据注释(18,2)
发布评论