From b1fb0cee9461689d569bcdf22960ba3d33584bed Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 9 Jul 2022 02:38:48 +0800 Subject: [PATCH] Add Storageable.WhereColumns(+2) --- .../Abstract/SaveableProvider/Storageable.cs | 14 ++++++++++++-- Src/Asp.Net/SqlSugar/Interface/IStorageable.cs | 2 ++ Src/Asp.Net/SqlSugar/Utilities/UtilConvert.cs | 12 ++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs b/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs index a63ba06c8..f08b800dc 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs @@ -16,6 +16,7 @@ namespace SqlSugar List dbDataList = new List(); List, bool>, string>> whereFuncs = new List, bool>, string>>(); Expression> whereExpression; + Func formatTime; private string asname { get; set; } public Storageable(List datas, SqlSugarProvider context) { @@ -261,6 +262,11 @@ namespace SqlSugar } } List wherecolumnList; + public IStorageable WhereColumns(Expression> columns, Func formatTime) + { + this.formatTime = formatTime; + return WhereColumns(columns); + } public IStorageable WhereColumns(Expression> columns) { if (columns == null) @@ -300,7 +306,11 @@ namespace SqlSugar var exp=ExpressionBuilderHelper.CreateNewFields(this.Context.EntityMaintenance.GetEntityInfo(), list); return this.WhereColumns(exp); } - + public IStorageable WhereColumns(string[] columns, Func formatTime) + { + this.formatTime = formatTime; + return WhereColumns(columns); + } private void SetConditList(List> itemList, List whereColumns, List conditList) { ; @@ -331,7 +341,7 @@ namespace SqlSugar FieldName = item.DbColumnName, ConditionalType = ConditionalType.Equal, CSharpTypeName=UtilMethods.GetTypeName(value), - FieldValue = value==null?"null":value.ObjToString(), + FieldValue = value==null?"null":value.ObjToString(formatTime), FieldValueConvertFunc=this.Context.CurrentConnectionConfig.DbType==DbType.PostgreSQL? UtilMethods.GetTypeConvert(value):null })); diff --git a/Src/Asp.Net/SqlSugar/Interface/IStorageable.cs b/Src/Asp.Net/SqlSugar/Interface/IStorageable.cs index b266ded9f..b2df5066b 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IStorageable.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IStorageable.cs @@ -9,7 +9,9 @@ namespace SqlSugar public interface IStorageable where T : class, new() { IStorageable WhereColumns(Expression> columns); + IStorageable WhereColumns(Expression> columns,Func formatTime); IStorageable WhereColumns(string [] columns); + IStorageable WhereColumns(string[] columns, Func formatTime); IStorageable SplitInsert(Func, bool> conditions, string message=null); IStorageable SplitUpdate(Func, bool> conditions, string message = null); IStorageable Saveable(string inserMessage = null, string updateMessage = null); diff --git a/Src/Asp.Net/SqlSugar/Utilities/UtilConvert.cs b/Src/Asp.Net/SqlSugar/Utilities/UtilConvert.cs index 42345a4b9..a645ee55b 100644 --- a/Src/Asp.Net/SqlSugar/Utilities/UtilConvert.cs +++ b/Src/Asp.Net/SqlSugar/Utilities/UtilConvert.cs @@ -66,6 +66,18 @@ namespace SqlSugar return thisValue == equalValue; } } + public static string ObjToString(this object thisValue,Func formatTime) + { + if (formatTime != null&&thisValue is DateTime) + { + var dt = Convert.ToDateTime(thisValue); + return formatTime(dt); + } + else + { + return thisValue.ObjToString(); + } + } public static string ObjToString(this object thisValue) { if (thisValue != null) return thisValue.ToString().Trim();