StringLength 与 MaxLength 属性 ASP.NET MVC with Entity Framework EF Code First [英] StringLength vs MaxLength attributes ASP.NET MVC with Entity Framework EF Code First
问题描述
[MaxLength]
和 [StringLength]
属性的行为有何不同?
What is the difference in behavior of [MaxLength]
and [StringLength]
attributes?
据我所知(除了 [MaxLength]
可以验证数组的最大长度)这些是相同的并且有些多余?
As far as I can tell (with the exception that [MaxLength]
can validate the maximum length of an array) these are identical and somewhat redundant?
推荐答案
MaxLength 用于实体框架在创建数据库时决定字符串值字段的大小.
MaxLength is used for the Entity Framework to decide how large to make a string value field when it creates the database.
来自 MSDN:
指定数组的最大长度或属性中允许的字符串数据.
Specifies the maximum length of array or string data allowed in a property.
StringLength 是用于验证的数据注释用户输入.
StringLength is a data annotation that will be used for validation of user input.
来自 MSDN:
指定最小值和最大值允许的字符长度在数据字段中.
Specifies the minimum and maximum length of characters that are allowed in a data field.
这篇关于StringLength 与 MaxLength 属性 ASP.NET MVC with Entity Framework EF Code First的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!