private void ResolveWhereLogic(ExpressionParameter parameter, ExpressionParameter baseParameter, MemberExpression expression, bool?isLeft, bool isSetTempData, bool isSingle) { string fieldName = string.Empty; if (isSetTempData) { if (ExpressionTool.IsConstExpression(expression)) { var value = ExpressionTool.GetMemberValue(expression.Member, expression); baseParameter.CommonTempData = value; } else { fieldName = GetName(parameter, expression, null, isSingle); baseParameter.CommonTempData = fieldName; } } else { if (ExpressionTool.IsConstExpression(expression)) { var value = ExpressionTool.GetMemberValue(expression.Member, expression); base.AppendValue(parameter, isLeft, value); } else { fieldName = GetName(parameter, expression, isLeft, isSingle); AppendMember(parameter, isLeft, fieldName); } } }
public IUpdateable <T> SetColumns(Expression <Func <T, bool> > columns) { CheckTranscodeing(); var binaryExp = columns.Body as BinaryExpression; Check.Exception(!binaryExp.NodeType.IsIn(ExpressionType.Equal), "No support {0}", columns.ToString()); Check.Exception(!(binaryExp.Left is MemberExpression) && !(binaryExp.Left is UnaryExpression), "No support {0}", columns.ToString()); Check.Exception(ExpressionTool.IsConstExpression(binaryExp.Left as MemberExpression), "No support {0}", columns.ToString()); var expResult = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.WhereSingle).GetResultString().Replace(")", " )").Replace("(", "( ").Trim().TrimStart('(').TrimEnd(')'); string key = SqlBuilder.GetNoTranslationColumnName(expResult); UpdateBuilder.SetValues.Add(new KeyValuePair <string, string>(SqlBuilder.GetTranslationColumnName(key), expResult)); this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => (UpdateParameterIsNull == false && IsPrimaryKey(it)) || UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase) || SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList(); AppendSets(); return(this); }
private void AppendModel(ExpressionParameter parameter, MethodCallExpressionModel model, Expression item) { parameter.CommonTempData = CommonTempDataType.Result; base.Expression = item; if (item.Type == UtilConstants.DateType && parameter.CommonTempData.ObjToString() == CommonTempDataType.Result.ToString() && item.ToString() == "DateTime.Now.Date") { parameter.CommonTempData = DateTime.Now.Date; } else if (IsDateDate(item)) { parameter.CommonTempData = GetNewExpressionValue(item); } else if (IsDateValue(item)) { parameter.CommonTempData = GetNewExpressionValue(item); } else if (model.Name == "ToString" && item is ConstantExpression && (item as ConstantExpression).Type.IsEnum()) { parameter.CommonTempData = item.ToString(); } else { base.Start(); } var methodCallExpressionArgs = new MethodCallExpressionArgs() { IsMember = parameter.ChildExpression is MemberExpression && !ExpressionTool.IsConstExpression(parameter.ChildExpression as MemberExpression), MemberName = parameter.CommonTempData }; if (methodCallExpressionArgs.IsMember && parameter.ChildExpression != null && parameter.ChildExpression.ToString() == "DateTime.Now") { methodCallExpressionArgs.IsMember = false; } var value = methodCallExpressionArgs.MemberName; if (methodCallExpressionArgs.IsMember) { var childExpression = parameter.ChildExpression as MemberExpression; if (childExpression.Expression != null && childExpression.Expression is ConstantExpression) { methodCallExpressionArgs.IsMember = false; } } if (IsDateDate(item) || IsDateValue(item)) { methodCallExpressionArgs.IsMember = true; } if (methodCallExpressionArgs.IsMember == false && (item is MethodCallExpression && item.ToString() == "GetDate()") || (item is UnaryExpression && ((UnaryExpression)item).Operand.ToString() == "GetDate()")) { var parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.MethodConst + this.Context.ParameterIndex; this.Context.ParameterIndex++; methodCallExpressionArgs.MemberName = value; methodCallExpressionArgs.MemberValue = null; } else if (methodCallExpressionArgs.IsMember == false) { var parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.MethodConst + this.Context.ParameterIndex; this.Context.ParameterIndex++; methodCallExpressionArgs.MemberName = parameterName; methodCallExpressionArgs.MemberValue = value; this.Context.Parameters.Add(new DbLiteParameter(parameterName, value)); } model.Args.Add(methodCallExpressionArgs); parameter.ChildExpression = null; }