예제 #1
0
        public override VfpExpression Visit(VfpOrExpression expression)
        {
            var list = OrComparisonGatherer.Gather(expression);

            if (!list.Any())
            {
                return(base.Visit(expression));
            }

            var comparison = list.Select(x => new {
                x.ExpressionKind,
                LeftExpression                     = x.Left,
                LeftDbConstantExpression           = ConstantGatherer.Gather(x.Left).FirstOrDefault(),
                RightExpression                    = x.Right,
                RightDbPropertyExpression          = PropertyGatherer.Gather(x.Right).FirstOrDefault(),
                RightDbVariableReferenceExpression = VariableReferenceGatherer.Gather(x.Right).FirstOrDefault()
            }).First();

            if (comparison.ExpressionKind != VfpExpressionKind.Equals && comparison.ExpressionKind != VfpExpressionKind.NotEquals)
            {
                return(base.Visit(expression));
            }

            if (comparison.LeftDbConstantExpression == null || comparison.RightDbPropertyExpression == null || comparison.RightDbVariableReferenceExpression == null)
            {
                return(base.Visit(expression));
            }

            var expressions = list.Select(x => new {
                x.ExpressionKind,
                LeftExpression                     = x.Left,
                LeftDbConstantExpression           = ConstantGatherer.Gather(x.Left).FirstOrDefault(),
                RightExpression                    = x.Right,
                RightDbPropertyExpression          = PropertyGatherer.Gather(x.Right).FirstOrDefault(),
                RightDbVariableReferenceExpression = VariableReferenceGatherer.Gather(x.Right).FirstOrDefault()
            })
                              .Where(x => x.LeftDbConstantExpression != null)
                              .Where(x => x.RightDbPropertyExpression != null)
                              .Where(x => x.RightDbVariableReferenceExpression != null)
                              .ToList();

            if (list.Count != expressions.Count)
            {
                return(base.Visit(expression));
            }

            if (!expressions.All(x => x.LeftDbConstantExpression.ConstantKind == comparison.LeftDbConstantExpression.ConstantKind &&
                                 x.LeftDbConstantExpression.ResultType == comparison.LeftDbConstantExpression.ResultType &&
                                 x.RightDbPropertyExpression.Property == comparison.RightDbPropertyExpression.Property &&
                                 x.RightDbVariableReferenceExpression.VariableName == comparison.RightDbVariableReferenceExpression.VariableName))
            {
                return(base.Visit(expression));
            }

            var inExpression = comparison.RightExpression.In(list.Select(x => x.Left).ToList().List());

            return(base.Visit(inExpression));
        }
        public override VfpExpression Visit(VfpComparisonExpression expression)
        {
            // Check the left expression to see if it contains a property expression.
            // Don't need to rewrite the comparison expression of the left side already contains a property expression.
            if (PropertyGatherer.Gather(expression.Left).Any())
            {
                return(expression);
            }

            // Check the right expression to see if it has a property expression.
            if (!PropertyGatherer.Gather(expression.Right).Any())
            {
                return(expression);
            }

            return(reverseExpression(expression));
        }
예제 #3
0
        public override VfpExpression Visit(VfpLikeExpression expression)
        {
            // Check the argument expression to see if it contains a property expression.
            // Don't need to rewrite the expression if the left side already contains a property expression.
            if (PropertyGatherer.Gather(expression.Argument).Any())
            {
                return(expression);
            }

            // Check the pattern expression to see if it has a property expression.
            if (!PropertyGatherer.Gather(expression.Pattern).Any())
            {
                return(expression);
            }

            return(VfpExpressionBuilder.Like(expression.ResultType,
                                             expression.Pattern,
                                             expression.Argument,
                                             expression.Escape));
        }