From 109454c56c568b96d31afa3768c10163ddc7e665 Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Mon, 19 Jul 2021 12:35:51 +0800 Subject: [PATCH] Update pgsql Storageable WhereColumn bug --- .../Abstract/SaveableProvider/Storageable.cs | 7 ++++-- Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs b/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs index 1b64010fa..e1a6babd7 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs @@ -189,7 +189,7 @@ namespace SqlSugar } } - private static void SetConditList(List> itemList, List whereColumns, List conditList) + private void SetConditList(List> itemList, List whereColumns, List conditList) { ; foreach (var dataItem in itemList) @@ -202,11 +202,14 @@ namespace SqlSugar int i = 0; foreach (var item in whereColumns) { + var value = item.PropertyInfo.GetValue(dataItem.Item, null); condition.ConditionalList.Add(new KeyValuePair(i==0?WhereType.Or :WhereType.And, new ConditionalModel() { FieldName = item.DbColumnName, ConditionalType = ConditionalType.Equal, - FieldValue = item.PropertyInfo.GetValue(dataItem.Item, null) + "" + FieldValue = value + "", + FieldValueConvertFunc=this.Context.CurrentConnectionConfig.DbType==DbType.PostgreSQL? + UtilMethods.GetTypeConvert(value):null })); ++i; } diff --git a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs index de80b0fdd..29edf7ed8 100644 --- a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs @@ -252,6 +252,31 @@ namespace SqlSugar return string.Format(" ({0}) {1} ", sql, shortName); } + public static Func GetTypeConvert(object value) + { + if (value is int || value is uint || value is int? || value is uint?) + { + return x => Convert.ToInt32(x); + } + else if (value is short || value is ushort || value is short? || value is ushort?) + { + return x => Convert.ToInt16(x); + } + else if (value is long || value is long? || value is ulong? || value is long?) + { + return x => Convert.ToInt64(x); + } + else if (value is DateTime|| value is DateTime?) + { + return x => Convert.ToDateTime(x); + } + else if (value is bool||value is bool?) + { + return x => Convert.ToBoolean(x); + } + return null; + } + internal static string GetParenthesesValue(string dbTypeName) { if (Regex.IsMatch(dbTypeName, @"\(.+\)"))