From e890b716cbb4d0964b7de413aae84a0a533d5d87 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Wed, 31 May 2017 01:29:25 +0800 Subject: [PATCH] - --- SqlServerTest/Demos/Query.cs | 4 ++++ .../QueryableProvider/QueryableProvider.cs | 2 +- .../ExpressionsToSql/Method/DefaultDbMethod.cs | 15 ++++++++++++--- SqlSugar/ExpressionsToSql/Method/NBORM.cs | 2 +- .../ResolveItems/MethodCallExpressionResolve.cs | 11 +++++++---- SqlSugar/Interface/IQueryable.cs | 2 +- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/SqlServerTest/Demos/Query.cs b/SqlServerTest/Demos/Query.cs index 2eabbb550..19ae32e7d 100644 --- a/SqlServerTest/Demos/Query.cs +++ b/SqlServerTest/Demos/Query.cs @@ -130,6 +130,10 @@ namespace OrmTest.Demo var isAny = db.Queryable().Where(it => it.Id == -1).Any(); var isAny2 = db.Queryable().Any(it => it.Id == -1); var getListByRename = db.Queryable().AS("Student").ToList(); + var in1 = db.Queryable().In(it=>it.Id,new int[] { 1, 2, 3 }).ToList(); + var in2 = db.Queryable().In(new int[] { 1, 2, 3 }).ToList(); + int[] array = new int[] { 1, 2 }; + var in3 = db.Queryable().Where(it=>NBORM.ContainsArray(array, it.Id)).ToList(); var group = db.Queryable().GroupBy(it => it.Id) .Having(it => NBORM.AggregateCount(it.Id) > 10) .Select(it => new { id = NBORM.AggregateCount(it.Id) }).ToList(); diff --git a/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index 2cf3b78d8..0bcab57a8 100644 --- a/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -141,7 +141,7 @@ namespace SqlSugar return this; } - public ISugarQueryable In(params object[] pkValues) + public ISugarQueryable In(params TParamter[] pkValues) { if (pkValues == null || pkValues.Length == 0) { diff --git a/SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs b/SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs index 871e3f57d..c521f9e42 100644 --- a/SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs +++ b/SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; @@ -39,12 +40,20 @@ namespace SqlSugar } public virtual string ContainsArray(MethodCallExpressionModel model) { - var inValues = (object[])model.Args[0].MemberValue; + var inValueIEnumerable = (IEnumerable)model.Args[0].MemberValue; + List inValues = new List(); + if (inValueIEnumerable != null) + { + foreach (var item in inValueIEnumerable) + { + inValues.Add(item); + } + } var value = model.Args[1].MemberName; string inValueString = null; - if (inValues != null && inValues.Length > 0) + if (inValues != null && inValues.Count > 0) { - inValueString = inValues.ToJoinSqlInVals(); + inValueString = inValues.ToArray().ToJoinSqlInVals(); } else { return " (1=2) "; diff --git a/SqlSugar/ExpressionsToSql/Method/NBORM.cs b/SqlSugar/ExpressionsToSql/Method/NBORM.cs index 5bbe38cc8..e87468b0c 100644 --- a/SqlSugar/ExpressionsToSql/Method/NBORM.cs +++ b/SqlSugar/ExpressionsToSql/Method/NBORM.cs @@ -13,7 +13,7 @@ namespace SqlSugar public static string ToUpper(object thisValue) { throw new NotImplementedException(); } public static string Trim(object thisValue) { throw new NotImplementedException(); } public static bool Contains(string thisValue, string parameterValue) { throw new NotImplementedException();} - public static bool ContainsArray(object [] thisValue, string parameterValue) { throw new NotImplementedException(); } + public static bool ContainsArray(T [] thisValue, object parameterValue) { throw new NotImplementedException(); } public static bool StartsWith(object thisValue, string parameterValue) { throw new NotImplementedException(); } public static bool EndsWith(object thisValue, string parameterValue) { throw new NotImplementedException(); } public new static bool Equals(object thisValue, object parameterValue) { throw new NotImplementedException(); } diff --git a/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs b/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs index b7120ced7..bd620bdfe 100644 --- a/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs +++ b/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs @@ -80,7 +80,8 @@ namespace SqlSugar IsMember = parameter.ChildExpression is MemberExpression, MemberName = parameter.CommonTempData }; - if (methodCallExpressionArgs.IsMember && parameter.ChildExpression != null && parameter.ChildExpression.ToString() == "DateTime.Now") { + if (methodCallExpressionArgs.IsMember && parameter.ChildExpression != null && parameter.ChildExpression.ToString() == "DateTime.Now") + { methodCallExpressionArgs.IsMember = false; } var value = methodCallExpressionArgs.MemberName; @@ -119,9 +120,11 @@ namespace SqlSugar case "Trim": return this.Context.DbMehtods.Trim(model); case "Contains": - return this.Context.DbMehtods.Contains(model); + return this.Context.DbMehtods.Contains(model); case "ContainsArray": - return this.Context.DbMehtods.ContainsArray(model); + var result = this.Context.DbMehtods.ContainsArray(model); + this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString()); + return result; case "Equals": return this.Context.DbMehtods.Equals(model); case "DateIsSame": @@ -143,7 +146,7 @@ namespace SqlSugar case "EndsWith": return this.Context.DbMehtods.EndsWith(model); case "ToInt32": - return this.Context.DbMehtods.ToInt32(model); + return this.Context.DbMehtods.ToInt32(model); case "ToInt64": return this.Context.DbMehtods.ToInt64(model); case "ToDate": diff --git a/SqlSugar/Interface/IQueryable.cs b/SqlSugar/Interface/IQueryable.cs index acb958bba..f7fe649bc 100644 --- a/SqlSugar/Interface/IQueryable.cs +++ b/SqlSugar/Interface/IQueryable.cs @@ -42,7 +42,7 @@ namespace SqlSugar //ISugarQueryable WhereIF(bool isWhere, Expression> expression); //ISugarQueryable WhereIF(bool isWhere, Expression> expression); //ISugarQueryable WhereIF(bool isWhere, Expression> expression); - ISugarQueryable In(params object[] pkValues); + ISugarQueryable In(params TParamter[] pkValues); T InSingle(object pkValue); ISugarQueryable In(string InFieldName, params FieldType[] inValues);