diff --git a/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs b/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs index 7cc66f2c4..a5321d6c1 100644 --- a/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs +++ b/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs @@ -434,6 +434,8 @@ namespace OrmTest.Demo var test39 = db.Queryable().Where(it => it.Id == 1 && (it.Id==1?true:false)).ToList(); var test40 = db.Queryable().Where(it => it.Id==1&&Convert.ToBoolean("true")).ToList(); var test41 = db.Queryable().Where(it => it.Id==((it.Id==1?2:3)==2?1:2)).ToList(); + var test42 = db.Queryable().Where(it => new int[] { 1, 2, 3 }.Contains(1)).ToList(); + var test43 = db.Queryable().Where(it => new int[] { 1, 2, 3 }.Contains(it.Id)).ToList(); } public static void Page() { diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/NewArrayExpessionResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/NewArrayExpessionResolve.cs index 5d640113c..2ad08a93c 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/NewArrayExpessionResolve.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/NewArrayExpessionResolve.cs @@ -20,7 +20,51 @@ namespace SqlSugar case ResolveExpressType.SelectMultiple: case ResolveExpressType.FieldSingle: case ResolveExpressType.FieldMultiple: - Check.ThrowNotSupportedException("NewArrayExpression"); + try + { + var value = ExpressionTool.DynamicInvoke(expression); + var isLeft = parameter.IsLeft; + var baseParameter = parameter.BaseParameter; + var isSetTempData = baseParameter.CommonTempData.HasValue() && baseParameter.CommonTempData.Equals(CommonTempDataType.Result); + if (isSetTempData) + { + baseParameter.CommonTempData = value; + } + else + { + var parentIsBinary = parameter.BaseParameter.CurrentExpression is BinaryExpression; + var parentIsRoot = parameter.BaseParameter.CurrentExpression is LambdaExpression; + var isBool = value != null && value.GetType() == UtilConstants.BoolType; + if (parentIsRoot && isBool) + { + this.Context.Result.Append(value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False()); + break; + } + if (parentIsBinary && isBool) + { + var isLogicOperator = + parameter.BaseExpression.NodeType == ExpressionType.And || + parameter.BaseExpression.NodeType == ExpressionType.AndAlso || + parameter.BaseExpression.NodeType == ExpressionType.Or || + parameter.BaseExpression.NodeType == ExpressionType.OrElse; + if (isLogicOperator) + { + AppendMember(parameter, isLeft, (value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False())); + break; + } + } + if (value == null && parentIsBinary) + { + parameter.BaseParameter.ValueIsNull = true; + value = this.Context.DbMehtods.Null(); + } + AppendValue(parameter, isLeft, value); + } + } + catch (Exception) + { + Check.ThrowNotSupportedException("NewArrayExpression"); + } break; case ResolveExpressType.ArraySingle: foreach (var item in expression.Expressions) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite index e063c0f26..f2f07cf5c 100644 Binary files a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite and b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite differ