StringLength VS MAXLENGTH属性ASP.NET MVC实体框架EF code首先 [英] StringLength vs MaxLength attributes ASP.NET MVC with Entity Framework EF Code First

查看:1920
本文介绍了StringLength VS MAXLENGTH属性ASP.NET MVC实体框架EF code首先的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么在行为的差异 [最大长度] [StringLength] 属性?

What is the difference in behavior of [MaxLength] and [StringLength] attributes?

这是相同的,有些多余?

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?

推荐答案

<一个href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.maxlengthattribute%28v=vs.103%29.aspx\">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.

<一个href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute.aspx\">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 VS MAXLENGTH属性ASP.NET MVC实体框架EF code首先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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