简体   繁体   English

EF:对数据类型映射的限制

[英]EF: Restriction on data types mapping

Is it possible to edit the error message of type of data on EF ? 是否可以在EF上编辑数据类型的错误消息?

For example, I've to display to the end-user that the value entered on ID's field must be integer . 例如,我要向最终用户显示the value entered on ID's field must be integer

public int ID { get; set; }

Thanks a lot !! 非常感谢 !!

You can use Range validator: 您可以使用Range验证器:

 [Range(int.MinValue, int.MaxValue, ErrorMessageResourceName = "IDMustBeInteger",
    ErrorMessageResourceType = typeof (Resources))]

You can use a regular expression annotation to validate digits only 您可以使用正则表达式注释来仅验证数字

[RegularExpression(@"^\d+$",ErrorMessage="the value entered on ID's field must be integer")]
public int MyInt { get; set; }

在此输入图像描述

It seems that you have two possible solutions for your problem: 您的问题似乎有两种可能的解决方案:

  1. You can write client validation to check this on client (using regexp or something else) 您可以编写客户端验证以在客户端上进行检查(使用regexp或其他)

  2. You can use custom ModelBinder to intercept default error. 您可以使用自定义ModelBinder拦截默认错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM