From 46f47922ddfa39764939287c21796386a988856c Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 27 Sep 2022 22:13:36 +0800 Subject: [PATCH] exp to sql : ids.Contains(it.Name,true) --- .../ExpressionsToSql/DbMethods/DefaultDbMethod.cs | 12 ++++++++++-- Src/Asp.Net/SqlSugar/Utilities/CommonExtensions.cs | 10 ++++++++++ Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs | 12 +++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs index 4de1230b7..556a6031e 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs @@ -99,9 +99,17 @@ namespace SqlSugar } var value = model.Args[1].MemberName; string inValueString = null; + var isNvarchar = model.Args.Count == 3; if (inValues != null && inValues.Count > 0) - { - inValueString = inValues.ToArray().ToJoinSqlInVals(); + { + if (isNvarchar&& model.Args[2].MemberValue.Equals(true)) + { + inValueString = inValues.ToArray().ToJoinSqlInValsN(); + } + else + { + inValueString = inValues.ToArray().ToJoinSqlInVals(); + } } if (inValueString.IsNullOrEmpty()) { diff --git a/Src/Asp.Net/SqlSugar/Utilities/CommonExtensions.cs b/Src/Asp.Net/SqlSugar/Utilities/CommonExtensions.cs index 11d1dd225..9164b2f8e 100644 --- a/Src/Asp.Net/SqlSugar/Utilities/CommonExtensions.cs +++ b/Src/Asp.Net/SqlSugar/Utilities/CommonExtensions.cs @@ -38,3 +38,13 @@ namespace SqlSugar } } } +namespace System.Collections.Generic +{ + public static class EnumerableExtensions + { + public static bool Contains(this IEnumerable thisValue, T likeKey, bool isNvarchar) + { + return thisValue.Contains(likeKey); + } + } +} \ No newline at end of file diff --git a/Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs b/Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs index 83ae52529..b221ac849 100644 --- a/Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs +++ b/Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs @@ -18,7 +18,17 @@ namespace SqlSugar return string.Join(",", array.Where(c => c != null).Select(it => it.ToSqlValue())); } } - + public static string ToJoinSqlInValsN(this T[] array) + { + if (array == null || array.Length == 0) + { + return ToSqlValue(string.Empty); + } + else + { + return string.Join(",", array.Where(c => c != null).Select(it => "N"+it.ToSqlValue())); + } + } public static string ToSqlValue(this object value) { if (value!=null&& UtilConstants.NumericalTypes.Contains(value.GetType()))