Browse Source

Support NewArrayExpession

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
7d0326cafd
  1. 2
      Src/Asp.Net/SqlServerTest/Demos/1_Query.cs
  2. 46
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/NewArrayExpessionResolve.cs
  3. BIN
      Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite

2
Src/Asp.Net/SqlServerTest/Demos/1_Query.cs

@ -434,6 +434,8 @@ namespace OrmTest.Demo
var test39 = db.Queryable<Student>().Where(it => it.Id == 1 && (it.Id==1?true:false)).ToList();
var test40 = db.Queryable<Student>().Where(it => it.Id==1&&Convert.ToBoolean("true")).ToList();
var test41 = db.Queryable<Student>().Where(it => it.Id==((it.Id==1?2:3)==2?1:2)).ToList();
var test42 = db.Queryable<Student>().Where(it => new int[] { 1, 2, 3 }.Contains(1)).ToList();
var test43 = db.Queryable<Student>().Where(it => new int[] { 1, 2, 3 }.Contains(it.Id)).ToList();
}
public static void Page()
{

46
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)

BIN
Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite

Binary file not shown.
Loading…
Cancel
Save