mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Add SqlFunc.ContainsArrayUseSqlParameters
This commit is contained in:
parent
cff0df9c11
commit
51af495f22
@ -78,6 +78,9 @@ namespace OrmTest
|
|||||||
CheckMan = saleOrderInfo.CheckMan,
|
CheckMan = saleOrderInfo.CheckMan,
|
||||||
CheckTime = DateTime.Now
|
CheckTime = DateTime.Now
|
||||||
}, o => o.OrderSn == saleOrderInfo.OrderSn && o.OrderStatus != 1);
|
}, o => o.OrderSn == saleOrderInfo.OrderSn && o.OrderStatus != 1);
|
||||||
|
|
||||||
|
var ids = Enumerable.Range(1, 11).ToList();
|
||||||
|
var list8=Db.Queryable<Order>().Where(it => SqlFunc.ContainsArrayUseSqlParameters(ids, it.Id)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class IEnumerbleContains
|
public static class IEnumerbleContains
|
||||||
|
@ -8,8 +8,9 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class MethodCallExpressionModel
|
public class MethodCallExpressionModel
|
||||||
{
|
{
|
||||||
public List<MethodCallExpressionArgs> Args { get; set; }
|
public List<MethodCallExpressionArgs> Args { get; set; }
|
||||||
public string Name { get; internal set; }
|
public string Name { get; set; }
|
||||||
|
public dynamic Data { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MethodCallExpressionArgs
|
public class MethodCallExpressionArgs
|
||||||
@ -17,6 +18,6 @@ namespace SqlSugar
|
|||||||
public bool IsMember { get; set; }
|
public bool IsMember { get; set; }
|
||||||
public object MemberName { get; set; }
|
public object MemberName { get; set; }
|
||||||
public object MemberValue { get; set; }
|
public object MemberValue { get; set; }
|
||||||
public Type Type { get; set; }
|
public Type Type { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,44 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual string ContainsArrayUseSqlParameters(MethodCallExpressionModel model)
|
||||||
|
{
|
||||||
|
var inValueIEnumerable = (IEnumerable)model.Args[0].MemberValue;
|
||||||
|
List<object> inValues = new List<object>();
|
||||||
|
if (inValueIEnumerable != null)
|
||||||
|
{
|
||||||
|
foreach (var item in inValueIEnumerable)
|
||||||
|
{
|
||||||
|
if (item != null && item.GetType().IsEnum())
|
||||||
|
{
|
||||||
|
inValues.Add(Convert.ToInt64(item));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
inValues.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var value = model.Args[1].MemberName;
|
||||||
|
string inValueString = null;
|
||||||
|
if (inValues != null && inValues.Count > 0)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < inValues.Count; i++)
|
||||||
|
{
|
||||||
|
inValueString += model.Data + "_" + i+",";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (inValueString.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
return " (1=2) ";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
inValueString=inValueString.TrimEnd(',');
|
||||||
|
return string.Format(" ({0} IN ({1})) ", value, inValueString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public virtual string Equals(MethodCallExpressionModel model)
|
public virtual string Equals(MethodCallExpressionModel model)
|
||||||
{
|
{
|
||||||
var parameter = model.Args[0];
|
var parameter = model.Args[0];
|
||||||
|
@ -20,6 +20,7 @@ namespace SqlSugar
|
|||||||
string Trim(MethodCallExpressionModel model);
|
string Trim(MethodCallExpressionModel model);
|
||||||
string Contains(MethodCallExpressionModel model);
|
string Contains(MethodCallExpressionModel model);
|
||||||
string ContainsArray(MethodCallExpressionModel model);
|
string ContainsArray(MethodCallExpressionModel model);
|
||||||
|
string ContainsArrayUseSqlParameters(MethodCallExpressionModel model);
|
||||||
string Equals(MethodCallExpressionModel model);
|
string Equals(MethodCallExpressionModel model);
|
||||||
string DateIsSameDay(MethodCallExpressionModel model);
|
string DateIsSameDay(MethodCallExpressionModel model);
|
||||||
string DateIsSameByType(MethodCallExpressionModel model);
|
string DateIsSameByType(MethodCallExpressionModel model);
|
||||||
|
@ -37,9 +37,21 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return thisValue.Contains(parameterValue);
|
return thisValue.Contains(parameterValue);
|
||||||
}
|
}
|
||||||
public static bool ContainsArray<T>(T[] thisValue, object parameterValue)
|
public static bool ContainsArray<T>(T[] thisValue, object InField)
|
||||||
{
|
{
|
||||||
return thisValue.Contains((T)parameterValue);
|
return thisValue.Contains((T)InField);
|
||||||
|
}
|
||||||
|
public static bool ContainsArray<T>(List<T> thisValue, object InField)
|
||||||
|
{
|
||||||
|
return thisValue.Contains((T)InField);
|
||||||
|
}
|
||||||
|
public static bool ContainsArrayUseSqlParameters<T>(List<T> thisValue, object InField)
|
||||||
|
{
|
||||||
|
return thisValue.Contains((T)InField);
|
||||||
|
}
|
||||||
|
public static bool ContainsArrayUseSqlParameters<T>(T[] thisValue, object InField)
|
||||||
|
{
|
||||||
|
return thisValue.Contains((T)InField);
|
||||||
}
|
}
|
||||||
public static bool StartsWith(string thisValue, string parameterValue)
|
public static bool StartsWith(string thisValue, string parameterValue)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -539,6 +540,30 @@ namespace SqlSugar
|
|||||||
var caResult = this.Context.DbMehtods.ContainsArray(model);
|
var caResult = this.Context.DbMehtods.ContainsArray(model);
|
||||||
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
|
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
|
||||||
return caResult;
|
return caResult;
|
||||||
|
case "ContainsArrayUseSqlParameters":
|
||||||
|
if (model.Args[0].MemberValue == null)
|
||||||
|
{
|
||||||
|
var first = this.Context.Parameters.FirstOrDefault(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
|
||||||
|
if (first.HasValue())
|
||||||
|
{
|
||||||
|
model.Args[0].MemberValue = first.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
model.Data =this.Context.SqlParameterKeyWord+"INP_"+this.Context.ParameterIndex;
|
||||||
|
this.Context.ParameterIndex++;
|
||||||
|
if (model.Args[0].MemberValue.HasValue())
|
||||||
|
{
|
||||||
|
var inValueIEnumerable = (IEnumerable)model.Args[0].MemberValue;
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in inValueIEnumerable)
|
||||||
|
{
|
||||||
|
this.Context.Parameters.Add(new SugarParameter(model.Data+"_"+i,item));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var caResult2 = this.Context.DbMehtods.ContainsArrayUseSqlParameters(model);
|
||||||
|
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
|
||||||
|
return caResult2;
|
||||||
case "Equals":
|
case "Equals":
|
||||||
return this.Context.DbMehtods.Equals(model);
|
return this.Context.DbMehtods.Equals(model);
|
||||||
case "DateIsSame":
|
case "DateIsSame":
|
||||||
|
Loading…
Reference in New Issue
Block a user