简体   繁体   English

数据验证无法通过数据注释进行

[英]data validation is not working through data annotations

I am trying to validate the length through data annotations like this 我正在尝试通过像这样的数据注释来验证长度

 [DataMember]
 [StringLength(7, ErrorMessage = "ClaimNumber cannot exceed length higher than 7")]
 public string claimNumber

Still error is not thrown if string of more lenght is passed. 如果传递更多长度的字符串,仍然不会引发错误。 Can any one please help with this? 有人可以帮忙吗? its with Entity framework. 其与实体框架。

您已经显示了一个字段,数据验证仅适用于属性。

Wcf has not data annotations validation out of the box. Wcf没有开箱即用的数据注释验证。 To add this you can use this nuget package: Wcf.AttributeValidation 要添加它,您可以使用以下nuget包: Wcf.AttributeValidation

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

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