Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
<format type="text/markdown"><![CDATA[

## Remarks
ASP.NET Dynamic Data enables CRUD (Create, Read, Update and Delete) operations in a data model. You can specify the minimum and maximum length of characters for each field when data is being inserted or updated. For character data types, the <xref:System.ComponentModel.DataAnnotations.StringLengthAttribute.MinimumLength%2A> and <xref:System.ComponentModel.DataAnnotations.StringLengthAttribute.MaximumLength%2A> properties identify the largest number of bytes that are required in order to store a string.


ASP.NET Dynamic Data enables CRUD (Create, Read, Update and Delete) operations in a data model. You can specify the minimum and maximum length of characters for each field when data is being inserted or updated. For character data types, the <xref:System.ComponentModel.DataAnnotations.StringLengthAttribute.MinimumLength%2A> and <xref:System.ComponentModel.DataAnnotations.StringLengthAttribute.MaximumLength%2A> properties identify the largest number of bytes that are required in order to store a string.

You can use [composite formatting](~/docs/standard/base-types/composite-formatting.md) placeholders in the error message:
{0} is the name of the property; {1} is the maximum length; and {2} is the minimum length.
The placeholders correspond to arguments that are passed to the <xref:System.String.Format%2A?displayProperty=nameWithType> method at runtime.

## Examples
The following example shows how to limit the number of characters in a field. This example works with the ThumbnailPhotoFileName field in the Products table in the AdventureWorksLT database. The field is limited 4 characters by applying the <xref:System.ComponentModel.DataAnnotations.StringLengthAttribute> attribute to the partial class that represents the Product entity.
Expand All @@ -59,6 +61,10 @@ public class ProductMetadata
[StringLength(4, ErrorMessage = "The ThumbnailPhotoFileName value cannot exceed 4 characters. ")]
public object ThumbnailPhotoFileName;

[ScaffoldColumn(true)]
[StringLength(4, ErrorMessage = "The {0} value cannot exceed {1} characters. ")]
public object PhotoFileName;

}
```

Expand All @@ -74,6 +80,10 @@ Public Class ProductMetadata
<StringLength(4, ErrorMessage := "The ThumbnailPhotoFileName value cannot exceed 4 characters. ")> _
Public ThumbnailPhotoFileName As Object

<ScaffoldColumn(True)> _
<StringLength(4, ErrorMessage := "The {0} value cannot exceed {1} characters. ")> _
Public PhotoFileName As Object

End Class
```

Expand Down Expand Up @@ -267,4 +277,4 @@ End Class
</Docs>
</Member>
</Members>
</Type>
</Type>