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 · 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:
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.
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.
Looks like you need to apply either [MaxLength] or [StringLength] attributes. Some additional possible negative factors of too wide columns are mentioned in @PaulWhite's answer here – Martin Smith
The MinLength attribute in Entity Framework Core is a data annotation attribute used to specify the minimum length of array or string data that must be present in the property for the model to be considered valid. Unlike MaxLength, the MinLength attribute does not affect the database schema.
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.