十进制的最佳数据注释(18,2)

编程入门 行业动态 更新时间:2024-10-24 06:38:18
本文介绍了十进制的最佳数据注释(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)

本文发布于:2023-07-27 12:01:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222332.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:注释   数据   十进制

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!