2017-01-07 21:54:51 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq.Expressions;
|
2017-01-08 20:38:03 +08:00
|
|
|
|
using System.Reflection;
|
2017-01-07 21:54:51 +08:00
|
|
|
|
using System.Text;
|
|
|
|
|
namespace SqlSugar
|
|
|
|
|
{
|
2017-01-08 15:41:54 +08:00
|
|
|
|
public class ConstantExpressionResolve : BaseResolve
|
2017-01-07 21:54:51 +08:00
|
|
|
|
{
|
2017-01-07 23:56:55 +08:00
|
|
|
|
public ConstantExpressionResolve(ExpressionParameter parameter) : base(parameter)
|
2017-01-07 21:54:51 +08:00
|
|
|
|
{
|
2017-01-08 20:38:03 +08:00
|
|
|
|
var expression = base.Expression as ConstantExpression;
|
2017-01-08 15:41:54 +08:00
|
|
|
|
var isLeft = parameter.IsLeft;
|
2017-07-17 01:00:59 +08:00
|
|
|
|
object value = ExpressionTool.GetValue(expression.Value);
|
2017-01-30 15:41:16 +08:00
|
|
|
|
var baseParameter = parameter.BaseParameter;
|
2017-01-31 20:56:19 +08:00
|
|
|
|
baseParameter.ChildExpression = expression;
|
2017-06-04 23:13:30 +08:00
|
|
|
|
var isSetTempData = baseParameter.CommonTempData.IsValuable() && baseParameter.CommonTempData.Equals(CommonTempDataType.Result);
|
2017-01-14 23:10:36 +08:00
|
|
|
|
switch (parameter.Context.ResolveType)
|
2017-01-08 15:41:54 +08:00
|
|
|
|
{
|
2017-01-14 23:10:36 +08:00
|
|
|
|
case ResolveExpressType.SelectSingle:
|
2017-05-24 20:35:23 +08:00
|
|
|
|
case ResolveExpressType.Update:
|
2017-01-14 23:10:36 +08:00
|
|
|
|
case ResolveExpressType.SelectMultiple:
|
2017-01-30 15:41:16 +08:00
|
|
|
|
baseParameter.CommonTempData = value;
|
2017-01-14 23:17:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case ResolveExpressType.WhereSingle:
|
|
|
|
|
case ResolveExpressType.WhereMultiple:
|
2017-01-30 15:41:16 +08:00
|
|
|
|
if (isSetTempData)
|
|
|
|
|
{
|
|
|
|
|
baseParameter.CommonTempData = value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-05-25 02:28:47 +08:00
|
|
|
|
var parentIsBinary = parameter.BaseParameter.CurrentExpression is BinaryExpression;
|
2017-06-04 00:37:30 +08:00
|
|
|
|
var parentIsRoot = parameter.BaseParameter.CurrentExpression is LambdaExpression;
|
2017-08-25 22:22:12 +08:00
|
|
|
|
var isBool = value != null && value.GetType() == UtilConstants.BoolType;
|
2017-07-11 13:42:38 +08:00
|
|
|
|
if (parentIsRoot && isBool)
|
2017-06-13 16:23:08 +08:00
|
|
|
|
{
|
2017-07-11 13:42:38 +08:00
|
|
|
|
this.Context.Result.Append(value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False());
|
2017-06-04 00:37:30 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-07-11 13:42:38 +08:00
|
|
|
|
if (parentIsBinary && isBool)
|
2017-06-13 16:23:08 +08:00
|
|
|
|
{
|
2017-06-28 12:13:32 +08:00
|
|
|
|
var isLogicOperator =
|
|
|
|
|
parameter.BaseExpression.NodeType == ExpressionType.And ||
|
|
|
|
|
parameter.BaseExpression.NodeType == ExpressionType.AndAlso ||
|
|
|
|
|
parameter.BaseExpression.NodeType == ExpressionType.Or ||
|
|
|
|
|
parameter.BaseExpression.NodeType == ExpressionType.OrElse;
|
|
|
|
|
if (isLogicOperator)
|
|
|
|
|
{
|
2017-07-11 13:42:38 +08:00
|
|
|
|
AppendMember(parameter, isLeft, (value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False()));
|
2017-06-28 12:13:32 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-06-13 16:23:08 +08:00
|
|
|
|
}
|
|
|
|
|
if (value == null && parentIsBinary)
|
|
|
|
|
{
|
2017-05-25 02:28:47 +08:00
|
|
|
|
parameter.BaseParameter.ValueIsNull = true;
|
2017-09-15 19:27:23 +08:00
|
|
|
|
value = this.Context.DbMehtods.Null();
|
2017-05-25 02:28:47 +08:00
|
|
|
|
}
|
2017-01-31 20:13:22 +08:00
|
|
|
|
AppendValue(parameter, isLeft, value);
|
2017-01-30 15:41:16 +08:00
|
|
|
|
}
|
2017-01-28 20:13:29 +08:00
|
|
|
|
break;
|
2017-01-14 23:10:36 +08:00
|
|
|
|
case ResolveExpressType.FieldSingle:
|
|
|
|
|
case ResolveExpressType.FieldMultiple:
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2017-01-08 15:41:54 +08:00
|
|
|
|
}
|
2017-01-07 21:54:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|