DBに入れたタイミングでチェックする(MaxLength)か、ユーザが画面から入力した際にチェックする(StringLength)か、の違い。
MaxLength is used for the Entity Framework to decide how large to make a string value field when it creates the database.
From MSDN:Specifies the maximum length of array or string data allowed in a property.
StringLength is a data annotation that will be used for validation of user input.
From MSDN:Specifies the minimum and maximum length of characters that are allowed in a data field.
StringLength vs MaxLength attributes ASP.NET MVC with Entity Framework EF Code First
最小入力値のチェックはMaxLength属性はMinLength属性にて、StringLength属性はMinimumLengthプロパティで設定。
[MaxLength(100)]
[MinLength(5)]
[StringLength(100,MinimumLength =5)]
public string updateByName { get; set; }
ErrorMessageの変数は以下の通り。
- {0} = Property Name
- {1} = Max Length
- {2} = Min Length
StringLength vs MaxLength attributes ASP.NET MVC with Entity Framework EF Code First - Stack Overflow
http://stackoverflow.com/questions/5717033/stringlength-vs-maxlength-attributes-asp-net-mvc-with-entity-framework-ef-code-f