public SearchParamTableExpressionQueryGenerator VisitMultiary(MultiaryExpression expression, object context)
        {
            foreach (var childExpression in expression.Expressions)
            {
                var handler = childExpression.AcceptVisitor(this, context);
                if (handler != null)
                {
                    return(handler);
                }
            }

            return(null);
        }
        public static void ValidateMultiaryExpression(
            Expression expression,
            MultiaryOperator multiaryOperator,
            params Action <Expression>[] valueValidators)
        {
            MultiaryExpression multiaryExpression = Assert.IsType <MultiaryExpression>(expression);

            Assert.Equal(multiaryOperator, multiaryExpression.MultiaryOperation);

            Assert.Collection(
                multiaryExpression.Expressions,
                valueValidators);
        }
Example #3
0
        public override Expression VisitMultiary(MultiaryExpression expression, object context)
        {
            expression = (MultiaryExpression)base.VisitMultiary(expression, context);
            if (expression.Expressions.Count == 1)
            {
                return(expression.Expressions[0]);
            }

            List <Expression> newExpressions = null;

            for (var i = 0; i < expression.Expressions.Count; i++)
            {
                Expression childExpression = expression.Expressions[i];
                if (childExpression is MultiaryExpression childMultiary && childMultiary.MultiaryOperation == expression.MultiaryOperation)
                {
                    EnsureAllocatedAndPopulated(ref newExpressions, expression.Expressions, i);
                    newExpressions.AddRange(childMultiary.Expressions);
                }
Example #4
0
        public override Expression VisitMultiary(MultiaryExpression expression, object context)
        {
            if (expression.MultiaryOperation == MultiaryOperator.And &&
                expression.Expressions.Count == 3 &&
                expression.Expressions[0] is BinaryExpression isLong &&
                isLong.FieldName == SqlFieldName.DateTimeIsLongerThanADay)
            {
                var left  = (BinaryExpression)expression.Expressions[1];
                var right = (BinaryExpression)expression.Expressions[2];

                return(Expression.And(
                           Expression.Equals(SqlFieldName.DateTimeIsLongerThanADay, left.ComponentIndex, false),
                           new BinaryExpression(left.BinaryOperator, FieldName.DateTimeEnd, left.ComponentIndex, left.Value),
                           new BinaryExpression(left.BinaryOperator, FieldName.DateTimeStart, left.ComponentIndex, ((DateTimeOffset)left.Value).AddTicks(-TimeSpan.TicksPerDay)),
                           new BinaryExpression(right.BinaryOperator, FieldName.DateTimeStart, right.ComponentIndex, right.Value)));
            }

            return(expression);
        }
        public override Expression VisitMultiary(MultiaryExpression expression, int context)
        {
            if (expression.MultiaryOperation != MultiaryOperator.And)
            {
                throw new InvalidOperationException("Or is not supported as a top-level expression");
            }

            List <Expression>      denormalizedPredicates = null;
            List <TableExpression> normalizedPredicates   = null;

            for (var i = 0; i < expression.Expressions.Count; i++)
            {
                Expression childExpression = expression.Expressions[i];
                if (TryGetNormalizedGenerator(childExpression, out var normalizedGenerator, out var tableExpressionKind))
                {
                    EnsureAllocatedAndPopulated(ref denormalizedPredicates, expression.Expressions, i);
                    EnsureAllocatedAndPopulated(ref normalizedPredicates, Array.Empty <TableExpression>(), 0);

                    normalizedPredicates.Add(new TableExpression(normalizedGenerator, childExpression, null, tableExpressionKind, tableExpressionKind == TableExpressionKind.Chain ? 1 : 0));
                }
Example #6
0
        public override SearchParameterQueryGeneratorContext VisitMultiary(MultiaryExpression expression, SearchParameterQueryGeneratorContext context)
        {
            if (expression.MultiaryOperation == MultiaryOperator.Or)
            {
                context.StringBuilder.Append('(');
            }

            context.StringBuilder.AppendDelimited(
                sb => sb.AppendLine().Append(expression.MultiaryOperation == MultiaryOperator.And ? "AND " : "OR "),
                expression.Expressions,
                (sb, childExpr) => childExpr.AcceptVisitor(this, context));

            if (expression.MultiaryOperation == MultiaryOperator.Or)
            {
                context.StringBuilder.Append(')');
            }

            context.StringBuilder.AppendLine();

            return(context);
        }
        public override Expression VisitMultiary(MultiaryExpression expression, int context)
        {
            if (expression.MultiaryOperation != MultiaryOperator.And)
            {
                throw new InvalidOperationException("Or is not supported as a top-level expression");
            }

            List <SearchParameterExpressionBase> resourceExpressions = null;
            List <SearchParamTableExpression>    tableExpressions    = null;

            for (var i = 0; i < expression.Expressions.Count; i++)
            {
                Expression childExpression = expression.Expressions[i];

                if (TryGetSearchParamTableExpressionQueryGenerator(childExpression, out SearchParamTableExpressionQueryGenerator tableExpressionGenerator, out SearchParamTableExpressionKind tableExpressionKind))
                {
                    EnsureAllocatedAndPopulatedChangeType(ref resourceExpressions, expression.Expressions, i);
                    EnsureAllocatedAndPopulated(ref tableExpressions, Array.Empty <SearchParamTableExpression>(), 0);

                    tableExpressions.Add(new SearchParamTableExpression(tableExpressionGenerator, childExpression, tableExpressionKind, tableExpressionKind == SearchParamTableExpressionKind.Chain ? 1 : 0));
                }