Пример #1
0
 protected override Expression BuildExpression(Expression expression)
 {
     expression = OrderByRewriter.Rewrite(expression);
     expression = base.BuildExpression(expression);
     expression = UnusedColumnRemover.Remove(expression);
     return(expression);
 }
Пример #2
0
        protected override Expression BuildExpression(Expression expression)
        {
            expression = OrderByRewriter.Rewrite(expression);
            expression = base.BuildExpression(expression);
            expression = SkipToRowNumberRewriter.Rewrite(expression);
            expression = OrderByRewriter.Rewrite(expression);

            return(expression);
        }
Пример #3
0
 protected override Expression BuildExpression(Expression expression)
 {
     // fix up any order-by's
     expression = OrderByRewriter.Rewrite(expression);
     expression = base.BuildExpression(expression);
     expression = CrossJoinIsolator.Isolate(expression);
     expression = SkipToNestedOrderByRewriter.Rewrite(expression);
     expression = OrderByRewriter.Rewrite(expression);
     expression = UnusedColumnRemover.Remove(expression);
     //expression = RedundantColumnRemover.Remove(expression);
     return(expression);
 }
        protected override Expression VisitSelect(SelectExpression select)
        {
            // select * from table order by x skip s take t
            // =>
            // select * from (select top s * from (select top s + t from table order by x) order by -x) order by x

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

            if (select.Skip != null && select.Take != null && select.OrderBy.Count > 0)
            {
                var skip         = select.Skip;
                var take         = select.Take;
                var skipPlusTake = PartialEvaluator.Eval(Expression.Add(skip, take));

                select = select.SetTake(skipPlusTake).SetSkip(null);
                select = select.AddRedundantSelect(new TableAlias());
                select = select.SetTake(take);

                // propogate order-bys to new layer
                select = (SelectExpression)OrderByRewriter.Rewrite(select);
                var inverted = select.OrderBy.Select(ob => new OrderExpression(
                                                         ob.OrderType == OrderType.Ascending ? OrderType.Descending : OrderType.Ascending,
                                                         ob.Expression
                                                         ));

                select = select.SetOrderBy(inverted);

                select = select.AddRedundantSelect(new TableAlias());
                select = select.SetTake(Expression.Constant(0)); // temporary
                select = (SelectExpression)OrderByRewriter.Rewrite(select);

                var reverted = select.OrderBy.Select(ob => new OrderExpression(
                                                         ob.OrderType == OrderType.Ascending ? OrderType.Descending : OrderType.Ascending,
                                                         ob.Expression
                                                         ));

                select = select.SetOrderBy(reverted);
                select = select.SetTake(null);
            }

            return(select);
        }