From d0d7d0bc7f1a7ffc0296b2541424ad63318a97b1 Mon Sep 17 00:00:00 2001 From: forget-the-bright Date: Wed, 23 Aug 2023 15:44:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Template/ModelFile.template | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/DatabasetoEntityclass/Template/ModelFile.template b/DatabasetoEntityclass/Template/ModelFile.template index 69d131d..c0242b8 100644 --- a/DatabasetoEntityclass/Template/ModelFile.template +++ b/DatabasetoEntityclass/Template/ModelFile.template @@ -1,4 +1,5 @@ using System; +using FluentValidation; using NCA_MES_Models.CommonUtils.DB.DBAttribute; namespace ${namespace_name} @@ -25,4 +26,20 @@ $end $end } + /// + /// 验证类 采用FluentValidation + /// 项目地址 https://github.com/FluentValidation/FluentValidation + /// 文档地址 https://docs.fluentvalidation.net/en/latest/start.html + /// + public class ${table_name}Validator : AbstractValidator<${table_name}> + { + public ${table_name}Validator() + { +$foreach(filedInfo in filedInfos) +$if(filedInfo["is_nullable"]=="true") + RuleFor(item => item.${filedInfo["field_name"]}).NotNull().WithMessage("${filedInfo["comment"]}不能为空"); +$end +$end + } + } } \ No newline at end of file