internal FromExpression(EngineType engineType) { _expressionContext = new SQLExpressionVisitorContenxt(engineType) { ParamPlaceHolderPrefix = SqlHelper.ParameterizedChar + "f__" }; }
private static object VisitLambda(LambdaExpression lambda, SQLExpressionVisitorContenxt context) { if (lambda.Body.NodeType == ExpressionType.MemberAccess && context.Seperator == " ") { MemberExpression m = (MemberExpression)lambda.Body; if (m.Expression != null) { object r = VisitMemberAccess(m, context); if (!(r is PartialSqlString)) { return(r); } if (!m.Expression.Type.IsValueType) { return(r.ToString() !); } //return $"{r}={context.DatabaesEngine.GetDbValueStatement(true, needQuoted: true)}"; return($"{r}=1"); } } return(Visit(lambda.Body, context)); }
private static object VisitBinary(BinaryExpression b, SQLExpressionVisitorContenxt context) { object left; object right; bool rightIsNull; string operand = BindOperant(b.NodeType); if (operand == "AND" || operand == "OR") { if (b.Left is MemberExpression m && m.Expression != null && m.Expression.NodeType == ExpressionType.Parameter) { //left = new PartialSqlString(string.Format(GlobalSettings.Culture, "{0}={1}", VisitMemberAccess(m, context), context.DatabaesEngine.GetDbValueStatement(true, needQuoted: true))); left = new PartialSqlString($"{VisitMemberAccess(m, context)}=1"); } else { left = Visit(b.Left, context); } if (b.Right is MemberExpression mm && mm.Expression != null && mm.Expression.NodeType == ExpressionType.Parameter) { right = new PartialSqlString($"{VisitMemberAccess(mm, context)}=1"); }
public static object Visit(Expression?exp, SQLExpressionVisitorContenxt context) { if (exp == null) { return(string.Empty); } switch (exp.NodeType) { case ExpressionType.Lambda: return(VisitLambda((LambdaExpression)exp, context)); case ExpressionType.MemberAccess: return(VisitMemberAccess((MemberExpression)exp, context)); case ExpressionType.Constant: return(VisitConstant((ConstantExpression)exp)); case ExpressionType.Add: case ExpressionType.AddChecked: case ExpressionType.Subtract: case ExpressionType.SubtractChecked: case ExpressionType.Multiply: case ExpressionType.MultiplyChecked: case ExpressionType.Divide: case ExpressionType.Modulo: case ExpressionType.And: case ExpressionType.AndAlso: case ExpressionType.Or: case ExpressionType.OrElse: case ExpressionType.LessThan: case ExpressionType.LessThanOrEqual: case ExpressionType.GreaterThan: case ExpressionType.GreaterThanOrEqual: case ExpressionType.Equal: case ExpressionType.NotEqual: case ExpressionType.Coalesce: case ExpressionType.ArrayIndex: case ExpressionType.RightShift: case ExpressionType.LeftShift: case ExpressionType.ExclusiveOr: return(VisitBinary((BinaryExpression)exp, context)); case ExpressionType.Negate: case ExpressionType.NegateChecked: case ExpressionType.Not: case ExpressionType.Convert: case ExpressionType.ConvertChecked: case ExpressionType.ArrayLength: case ExpressionType.Quote: case ExpressionType.TypeAs: return(VisitUnary((UnaryExpression)exp, context)); case ExpressionType.Parameter: return(VisitParameter((ParameterExpression)exp)); case ExpressionType.Call: return(VisitMethodCall((MethodCallExpression)exp, context)); case ExpressionType.New: return(VisitNew((NewExpression)exp, context)); case ExpressionType.NewArrayInit: case ExpressionType.NewArrayBounds: return(VisitNewArray((NewArrayExpression)exp, context)); case ExpressionType.MemberInit: return(VisitMemberInit((MemberInitExpression)exp)); default: return(exp.ToString()); } }