From 499dec9569e2dbadcba6679fd7a9f524db88fa5b Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 13 Aug 2024 11:02:48 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E4=BA=BA=E5=A4=A7=E9=87=91=E4=BB=93[S?= =?UTF-8?q?qlServer]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MethodCallExpressionResolve_BaseDateFomat.cs | 4 ++++ .../MethodCallExpressionResolve_Helper.cs | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_BaseDateFomat.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_BaseDateFomat.cs index c45d8a676..1ba58c6ac 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_BaseDateFomat.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_BaseDateFomat.cs @@ -20,6 +20,10 @@ namespace SqlSugar } else if (IsOracle() || IsPg()) { + if (this.Context?.SugarContext?.Context?.CurrentConnectionConfig?.MoreSettings?.DatabaseModel == DbType.SqlServer) + { + return string.Format("FORMAT({0},'{1}','en-US')", value, formatString); + } if (!(formatString?.Contains("24") == true)) { formatString = formatString.Replace("HH", "hh24"); diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs index 364f073d5..8a76bd577 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs @@ -1,4 +1,4 @@ -using System; + using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -786,6 +786,10 @@ namespace SqlSugar if (model.Args.Count > 1) { var dateString2 = this.Context.DbMehtods.GetDateString(model.Args.First().MemberName.ObjToString(), model.Args.Last().MemberValue.ObjToString()); + if (IsSqlServerModel()) + { + return string.Format("FORMAT({0},'{1}','en-US')", model.Args.First().MemberName.ObjToString(), model.Args.Last().MemberValue.ObjToString()); + } if (dateString2 != null) return dateString2; return GeDateFormat(model.Args.Last().MemberValue.ObjToString(), model.Args.First().MemberName.ObjToString()); } @@ -999,6 +1003,11 @@ namespace SqlSugar return null; } + private bool IsSqlServerModel() + { + return this.Context?.SugarContext?.Context?.CurrentConnectionConfig?.MoreSettings?.DatabaseModel == DbType.SqlServer; + } + private string GetLike(string result, bool iLike) { if (iLike)