当前位置: 移动技术网 > IT编程>开发语言>.net > 9.9 翻译系列:数据注解特性之--MaxLength 【EF 6 Code-First系列】

9.9 翻译系列:数据注解特性之--MaxLength 【EF 6 Code-First系列】

2019年04月10日  | 移动技术网IT编程  | 我要评论

色欲无边,绯闻少女第一季下载,zt3

原文链接:

maxlength特性指定了属性的值所允许的最大值,然后在数据库中就生成相应列的最大值。maxlength特性可以应用于实体的string类型的属性和byte[]数组类型的属性上。

如果maxlength特性,应用在其他类型的属性上就报错,例如下面的图中例子:
enter description here
enter description here

using system.componentmodel.dataannotations;
    
public class student
{
    public int studentid { get; set; }
    [maxlength(50)]
    public string studentname { get; set; }
        
}

上面代码例子中,maxlength(50)应用在studentname属性上,指定studentname的属性值不能超过50个字符长度。
enter description here

ef将会检查标识了maxlength特性的属性值,如果长度超过了指定的长度,就会报错,ef6报错:system.data.entity.validation.dbentityvalidationexception ,ef core报错:microsoft.entityframeworkcore.dbupdateexception.

请注意:maxlength特性, mvc中,用于验证属性的值,了解更多详情请看这篇文章: 。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网