Search results
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. edited Apr 19, 2011 at 13:46.
25 lut 2014 · Specifies the minimum and maximum length of characters that are allowed in a data field. In my testing, StringLength works for both client validation and for Entity Framework (including EF Migrations). It’s an easy change as well, here’s the new code: [Required] [StringLength(30)] public string Name { get; set; }
MaxLength attribute is specifically for specifying the maximum length of a string property and is from the System.ComponentModel.DataAnnotations.Schema namespace. It allows you to specify only the maximum length constraint. Example:
The MaxLength attribute specifies the maximum length of data value allowed for a property which in turn sets the size of a corresponding column in the database. It can be applied to the string or byte[] properties of an entity.
The StringLength Data Annotation Attribute in Entity Framework can be applied to the string or Byte[] properties of an entity class. It is similar to the MaxLength and MinLength Attributes i.e. we can set both MinLength and MaxLength using this attribute.
The StringLength attribute can be applied to the string properties of an entity class. It specifies the maximum characters allowed for a string property which in turn sets the size of a corresponding column (nvarchar in SQL Server) in the database.
MaxLength and MinLength Attribute in Entity Framework. The MaxLength Data Annotation Attribute in Entity Framework specifies the maximum length of data value that can be allowed for a property. This MaxLength Attribute will set the size of the corresponding database table column in the database.