IEntity参数,不需要验证子级
This commit is contained in:
parent
b20e034513
commit
f648899d49
|
@ -0,0 +1,20 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
|
||||
using NewLife.Reflection;
|
||||
using XCode;
|
||||
|
||||
namespace NewLife.Cube;
|
||||
|
||||
/// <summary>实体验证元数据提供者</summary>
|
||||
public class EntityValidationMetadataProvider : IValidationMetadataProvider
|
||||
{
|
||||
/// <summary>创建验证元数据</summary>
|
||||
public void CreateValidationMetadata(ValidationMetadataProviderContext context)
|
||||
{
|
||||
// IEntity参数,不需要验证子级
|
||||
if (context.Key.ModelType.As<IEntity>())
|
||||
{
|
||||
context.ValidationMetadata.ValidateChildren = false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -125,6 +125,9 @@ public static class CubeService
|
|||
options.ModelBinderProviders.Insert(0, new EntityModelBinderProvider());
|
||||
|
||||
options.MaxValidationDepth = 16;
|
||||
|
||||
// 添加实体验证元数据提供者,取消实体类的DataAnnotations验证
|
||||
options.ModelMetadataDetailsProviders.Add(new EntityValidationMetadataProvider());
|
||||
});
|
||||
|
||||
services.AddCustomApplicationParts();
|
||||
|
|
Loading…
Reference in New Issue