From 4cb432d7012fa9fc61ffc2b34c64a74d207baae9 Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Mon, 11 Mar 2019 08:47:24 -0700 Subject: [PATCH 1/4] Note that you can use string.Format placeholders From https://github.com/aspnet/Docs/issues/10546 --- .../StringLengthAttribute.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml b/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml index 002bd74d7a7..eb7a17a8549 100644 --- a/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml +++ b/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml @@ -38,7 +38,7 @@ and 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 and properties identify the largest number of bytes that are required in order to store a string. You can use `String.Format` placeholders in the error message: {0} is the name of the property; {1} is the maximum length; and {2} is the minimum length." @@ -267,4 +267,4 @@ End Class - \ No newline at end of file + From d467dc467f9492f85f465c1484cfac400a8c9fde Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Mon, 11 Mar 2019 11:24:44 -0700 Subject: [PATCH 2/4] Add line break --- .../StringLengthAttribute.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml b/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml index eb7a17a8549..f02d0b60ce1 100644 --- a/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml +++ b/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml @@ -38,7 +38,9 @@ and properties identify the largest number of bytes that are required in order to store a string. You can use `String.Format` placeholders in the error message: {0} is the name of the property; {1} is the maximum length; and {2} is the minimum length." + 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 and properties identify the largest number of bytes that are required in order to store a string. + + You can use `String.Format` placeholders in the error message: {0} is the name of the property; {1} is the maximum length; and {2} is the minimum length." From 28399ba947be8c7fd35596e64eb8d9702dd011f1 Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Mon, 11 Mar 2019 11:50:01 -0700 Subject: [PATCH 3/4] feedback --- .../StringLengthAttribute.xml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml b/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml index f02d0b60ce1..ae12e16454f 100644 --- a/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml +++ b/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml @@ -40,9 +40,9 @@ ## 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 and properties identify the largest number of bytes that are required in order to store a string. - You can use `String.Format` placeholders in the error message: {0} is the name of the property; {1} is the maximum length; and {2} is the minimum length." - - +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 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 attribute to the partial class that represents the Product entity. @@ -61,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; + } ``` @@ -76,6 +80,10 @@ Public Class ProductMetadata _ Public ThumbnailPhotoFileName As Object + _ + _ + Public ThumbnailPhotoFileName As Object + End Class ``` From d6e2e74f8aa805a9bb723bdb9e5e00d55c6219c1 Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Mon, 11 Mar 2019 13:54:27 -0700 Subject: [PATCH 4/4] make vb example consistent with c# --- .../StringLengthAttribute.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml b/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml index ae12e16454f..3e78b6a25c1 100644 --- a/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml +++ b/xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml @@ -82,7 +82,7 @@ Public Class ProductMetadata _ _ - Public ThumbnailPhotoFileName As Object + Public PhotoFileName As Object End Class ```