bool CompareConditions(SelectQuery.Condition cond1, SelectQuery.Condition cond2) { if (cond1.ElementType != cond2.ElementType) { return(false); } if (cond1.Predicate.ElementType != cond2.Predicate.ElementType) { return(false); } switch (cond1.Predicate.ElementType) { case QueryElementType.IsNullPredicate: { var isNull1 = (SelectQuery.Predicate.IsNull)cond1.Predicate; var isNull2 = (SelectQuery.Predicate.IsNull)cond2.Predicate; return(isNull1.IsNot == isNull2.IsNot && CompareExpressions(isNull1.Expr1, isNull2.Expr1) == true); } case QueryElementType.ExprExprPredicate: { var expr1 = (SelectQuery.Predicate.ExprExpr)cond1.Predicate; var expr2 = (SelectQuery.Predicate.ExprExpr)cond2.Predicate; return(CompareExpressions(expr1, expr2)); } } return(false); }
public override ISqlExpression GetSubQuery(IBuildContext context) { if (_subQuerySql == null) { var cond = new SelectQuery.Condition( _methodCall.Method.Name == "All", new SelectQuery.Predicate.FuncLike(SqlFunction.CreateExists(SelectQuery))); _subQuerySql = new SelectQuery.SearchCondition(cond); } return(_subQuerySql); }
bool?EvaluateLogical(SelectQuery.Condition condition) { switch (condition.ElementType) { case QueryElementType.Condition: { var expr = condition.Predicate as SelectQuery.Predicate.ExprExpr; if (expr != null && expr.Operator == SelectQuery.Predicate.Operator.Equal) { return(CompareExpressions(expr.Expr1, expr.Expr2)); } break; } } return(null); }
public override ISqlExpression GetSubQuery(IBuildContext context) { if (_subQuerySql == null) { var args = _methodCall.Method.GetGenericArguments(); var param = Expression.Parameter(args[0], "param"); var expr = _methodCall.Arguments[1]; var condition = Expression.Lambda(ExpressionBuilder.Equal(Builder.MappingSchema, param, expr), param); IBuildContext ctx = new ExpressionContext(Parent, Sequence, condition); ctx = Builder.GetContext(ctx, expr) ?? ctx; Builder.ReplaceParent(ctx, this); SelectQuery.Condition cond; if (Sequence.SelectQuery != SelectQuery && (ctx.IsExpression(expr, 0, RequestFor.Field).Result || ctx.IsExpression(expr, 0, RequestFor.Expression).Result)) { Sequence.ConvertToIndex(null, 0, ConvertFlags.All); var ex = Builder.ConvertToSql(ctx, _methodCall.Arguments[1]); cond = new SelectQuery.Condition(false, new SelectQuery.Predicate.InSubQuery(ex, false, SelectQuery)); } else { var sequence = Builder.BuildWhere(Parent, Sequence, condition, true); cond = new SelectQuery.Condition(false, new SelectQuery.Predicate.FuncLike(SqlFunction.CreateExists(sequence.SelectQuery))); } _subQuerySql = new SelectQuery.SearchCondition(cond); } return(_subQuerySql); }
void AddSearchCondition(SelectQuery.SearchCondition search, SelectQuery.Condition condition) { AddSearchConditions(search, new[] { condition }); }