From f8ff9c7ea55ef19d70fde696da8f7e23289ca5fa Mon Sep 17 00:00:00 2001 From: maliming Date: Sat, 24 Oct 2020 16:34:48 +0800 Subject: [PATCH 1/2] Do not validate for primitive objects. --- .../DataAnnotationObjectValidationContributor.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/DataAnnotationObjectValidationContributor.cs b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/DataAnnotationObjectValidationContributor.cs index 797721bea3..25b59fbbcf 100644 --- a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/DataAnnotationObjectValidationContributor.cs +++ b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/DataAnnotationObjectValidationContributor.cs @@ -45,12 +45,18 @@ namespace Volo.Abp.Validation AddErrors(errors, validatingObject); //Validate items of enumerable - if (validatingObject is IEnumerable) + if (validatingObject is IEnumerable enumerable) { - if (!(validatingObject is IQueryable)) + if (!(enumerable is IQueryable)) { - foreach (var item in (validatingObject as IEnumerable)) + foreach (var item in enumerable) { + //Do not recursively validate for primitive objects + if (TypeHelper.IsPrimitiveExtended(item.GetType())) + { + break; + } + ValidateObjectRecursively(errors, item, currentDepth + 1); } } @@ -124,4 +130,4 @@ namespace Volo.Abp.Validation } } } -} \ No newline at end of file +} From 3c6b60d7bed9892a8db78b3f1e687edeb6012024 Mon Sep 17 00:00:00 2001 From: maliming Date: Sat, 24 Oct 2020 16:41:05 +0800 Subject: [PATCH 2/2] Update Validation.md --- docs/en/Validation.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/en/Validation.md b/docs/en/Validation.md index 15c3f13412..c4821adf65 100644 --- a/docs/en/Validation.md +++ b/docs/en/Validation.md @@ -112,6 +112,29 @@ namespace Acme.BookStore > ABP framework uses the [dynamic proxying / interception](Dynamic-Proxying-Interceptors.md) system to perform the validation. In order to make it working, your method should be **virtual** or your service should be injected and used over an **interface** (like `IMyService`). +#### Enabling/Disabling Validation + +You can use the `[DisableValidation]` to disable it for methods, classs and properties. + +````csharp +[DisableValidation] +public Void MyMethod() +{ +} + +[DisableValidation] +public class InputClass +{ + public string MyProperty { get; set; } +} + +public class InputClass +{ + [DisableValidation] + public string MyProperty { get; set; } +} +```` + ### AbpValidationException Once ABP determines a validation error, it throws an exception of type `AbpValidationException`. Your application code can throw `AbpValidationException`, but most of the times it is not needed. @@ -155,4 +178,4 @@ public class MyObjectValidationContributor ## FluentValidation Integration -Volo.Abp.FluentValidation package integrates the FluentValidation library to the validation system (by implementing the `IObjectValidationContributor`). See the [FluentValidation Integration document](FluentValidation.md) for more. \ No newline at end of file +Volo.Abp.FluentValidation package integrates the FluentValidation library to the validation system (by implementing the `IObjectValidationContributor`). See the [FluentValidation Integration document](FluentValidation.md) for more.