From 3f9d2a48bdf68fb0bb2ca7d4e6c2a9fd4adb1161 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 8 Apr 2022 11:47:51 +0800 Subject: [PATCH] Db.First support string append "?" --- .../Abstract/DbFirstProvider/DbFirstProvider.cs | 12 +++++++++++- Src/Asp.Net/SqlSugar/Interface/IDbFirst.cs | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs index ce03931d2..82a3cf298 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs @@ -21,6 +21,7 @@ namespace SqlSugar private bool IsDefaultValue { get; set; } private Func WhereColumnsfunc; private Func FormatFileNameFunc { get; set; } + private bool IsStringNullable {get;set;} private ISqlBuilder SqlBuilder { get @@ -56,6 +57,11 @@ namespace SqlSugar } #region Setting Template + public IDbFirst StringNullable() + { + IsStringNullable = true; + return this; + } public IDbFirst SettingClassDescriptionTemplate(Func func) { this.ClassDescriptionTemplate = func(this.ClassDescriptionTemplate); @@ -421,12 +427,16 @@ namespace SqlSugar } if (result == "Int32") { - result = "int"; + result = item.IsNullable?"int?":"int"; } if (result == "String") { result = "string"; } + if (result == "string" && item.IsNullable && IsStringNullable) + { + result = result + "?"; + } return result; } private string GetPropertyTypeConvert(DbColumnInfo item) diff --git a/Src/Asp.Net/SqlSugar/Interface/IDbFirst.cs b/Src/Asp.Net/SqlSugar/Interface/IDbFirst.cs index 381bb169b..2c4883610 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IDbFirst.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IDbFirst.cs @@ -24,5 +24,6 @@ namespace SqlSugar Dictionary ToClassStringList(string nameSpace = "Models"); void Init(); IDbFirst FormatFileName(Func formatFileNameFunc); + IDbFirst StringNullable(); } }