我有一个这样的模型:
public int Id { get; set; } [required] [StringLength(50,MinimumLength = 3)] public string Title { get; set; } [required] [StringLength(50,MinimumLength = 3)] public string Slug { get; set; } [required] [StringLength(100,MinimumLength = 3)] public string Body { get; set; }
正如您在Body中看到的那样,我将限制设置为100,但在数据库中,此列为varchar(max).我可以将长度与列的varchar(max)相匹配?
解决方法
您有两种选择:
(1)使用int.MaxLength作为StringLengthAttribute构造函数的maximumLength参数:
[required] [StringLength(int.MaxValue,MinimumLength = 3)] public string Body { get; set; }
(2)使用MaxLengthAttribute w / o参数另外装饰属性(将忽略StringLengthAttribute的值):
[required] [StringLength(100,MinimumLength = 3)] [MaxLength] public string Body { get; set; }
原文地址:https://www.jb51.cc/csharp/243421.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。