StringLength 与 MaxLength 属性 ASP.NET MVC with Entity Framework EF Code First [英] StringLength vs MaxLength attributes ASP.NET MVC with Entity Framework EF Code First

查看:40
本文介绍了StringLength 与 MaxLength 属性 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆