Browse Source

exp to sql : ids.Contains(it.Name,true)

SqlSugar5
sunkaixuan 2 years ago
parent
commit
46f47922dd
  1. 8
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  2. 10
      Src/Asp.Net/SqlSugar/Utilities/CommonExtensions.cs
  3. 12
      Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs

8
Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs

@ -99,10 +99,18 @@ namespace SqlSugar
} }
var value = model.Args[1].MemberName; var value = model.Args[1].MemberName;
string inValueString = null; string inValueString = null;
var isNvarchar = model.Args.Count == 3;
if (inValues != null && inValues.Count > 0) if (inValues != null && inValues.Count > 0)
{
if (isNvarchar&& model.Args[2].MemberValue.Equals(true))
{
inValueString = inValues.ToArray().ToJoinSqlInValsN();
}
else
{ {
inValueString = inValues.ToArray().ToJoinSqlInVals(); inValueString = inValues.ToArray().ToJoinSqlInVals();
} }
}
if (inValueString.IsNullOrEmpty()) if (inValueString.IsNullOrEmpty())
{ {
return " (1=2) "; return " (1=2) ";

10
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<T>(this IEnumerable<T> thisValue, T likeKey, bool isNvarchar)
{
return thisValue.Contains(likeKey);
}
}
}

12
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())); return string.Join(",", array.Where(c => c != null).Select(it => it.ToSqlValue()));
} }
} }
public static string ToJoinSqlInValsN<T>(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) public static string ToSqlValue(this object value)
{ {
if (value!=null&& UtilConstants.NumericalTypes.Contains(value.GetType())) if (value!=null&& UtilConstants.NumericalTypes.Contains(value.GetType()))

Loading…
Cancel
Save