예제 #1
0
        public static bool FindExists(Expression expression, Predicate<Expression> isMatch)
        {
            var finder = new ExpressionsFinder(isMatch, true);

            finder.Visit(expression);

            return finder.results.Count > 0;
        }
예제 #2
0
        public static Expression First(Expression expression, Predicate<Expression> isMatch)
        {
            var finder = new ExpressionsFinder(isMatch, true);

            finder.Visit(expression);

            return finder.results.FirstOrDefault();
        }
예제 #3
0
        public static List<Expression> FindAll(Expression expression, Predicate<Expression> isMatch)
        {
            var finder = new ExpressionsFinder(isMatch, false);

            finder.Visit(expression);

            return finder.results;
        }
예제 #4
0
        public static List <Expression> FindAll(Expression expression, Predicate <Expression> isMatch)
        {
            var finder = new ExpressionsFinder(isMatch, false);

            finder.Visit(expression);

            return(finder.results);
        }
예제 #5
0
        public static Expression First(Expression expression, Predicate <Expression> isMatch)
        {
            var finder = new ExpressionsFinder(isMatch, true);

            finder.Visit(expression);

            return(finder.results.FirstOrDefault());
        }
예제 #6
0
        public static bool FindExists(Expression expression, Predicate <Expression> isMatch)
        {
            var finder = new ExpressionsFinder(isMatch, true);

            finder.Visit(expression);

            return(finder.results.Count > 0);
        }
예제 #7
0
        protected override Expression VisitSelect(SqlSelectExpression select)
        {
            var saveIsOuterMostSelect = this.isOuterMostSelect;

            try
            {
                this.isOuterMostSelect = false;

                select = (SqlSelectExpression)base.VisitSelect(select);

                var hasOrderBy = select.OrderBy != null && select.OrderBy.Count > 0;

                if (hasOrderBy)
                {
                    this.PrependOrderings(select.OrderBy.Select(c => (SqlOrderByExpression)c));
                }

                var canHaveOrderBy     = saveIsOuterMostSelect && !ExpressionsFinder.FindExists(select, c => c.NodeType == (ExpressionType)SqlExpressionType.Aggregate || c.NodeType == (ExpressionType)SqlExpressionType.AggregateSubquery);
                var canPassOnOrderings = !saveIsOuterMostSelect;

                var columns = select.Columns;
                IEnumerable <Expression> orderings = (canHaveOrderBy) ? this.gatheredOrderings : null;

                if (this.gatheredOrderings != null)
                {
                    if (canPassOnOrderings)
                    {
                        var producedAliases = AliasesProduced.Gather(select.From);
                        var project         = this.RebindOrderings(this.gatheredOrderings, select.Alias, producedAliases, select.Columns);

                        this.gatheredOrderings = project.Orderings;

                        columns = project.Columns;
                    }
                    else
                    {
                        this.gatheredOrderings = null;
                    }
                }

                if (canHaveOrderBy && (orderings != select.OrderBy || columns != select.Columns))
                {
                    select = new SqlSelectExpression(select.Type, select.Alias, columns, select.From, select.Where, orderings, select.GroupBy, select.Distinct, select.Skip, select.Take, select.ForUpdate);
                }

                return(select);
            }
            finally
            {
                this.isOuterMostSelect = saveIsOuterMostSelect;
            }
        }