public static SelectExpression RemoveOrderExpression(this SelectExpression select, OrderExpression ordering) { if ((select.OrderBy != null) && (select.OrderBy.Count > 0)) { List <OrderExpression> orderBy = new List <OrderExpression>(select.OrderBy); orderBy.Remove(ordering); return(select.SetOrderBy(orderBy)); } return(select); }
public static SelectExpression AddOrderExpression(this SelectExpression select, OrderExpression ordering) { List <OrderExpression> orderBy = new List <OrderExpression>(); if (select.OrderBy != null) { orderBy.AddRange(select.OrderBy); } orderBy.Add(ordering); return(select.SetOrderBy(orderBy)); }
protected override Expression VisitSelect(SelectExpression selectExpression) { selectExpression = (SelectExpression)base.VisitSelect(selectExpression); if (((selectExpression.Skip != null) && (selectExpression.Take != null)) && (selectExpression.OrderBy.Count > 0)) { Expression skip = selectExpression.Skip; Expression take = selectExpression.Take; Expression expression3 = PartialEvaluator.Eval(Expression.Add(skip, take)); selectExpression = selectExpression.SetTake(expression3).SetSkip(null); selectExpression = selectExpression.AddRedundantSelect(this.language, new TableAlias()); selectExpression = selectExpression.SetTake(take); selectExpression = (SelectExpression)OrderByRewriter.Rewrite(this.language, selectExpression); IEnumerable <OrderExpression> orderBy = from ob in selectExpression.OrderBy select new OrderExpression((ob.OrderType == OrderType.Ascending) ? OrderType.Descending : OrderType.Ascending, ob.Expression); selectExpression = selectExpression.SetOrderBy(orderBy); selectExpression = selectExpression.AddRedundantSelect(this.language, new TableAlias()); selectExpression = selectExpression.SetTake(Expression.Constant(0)); selectExpression = (SelectExpression)OrderByRewriter.Rewrite(this.language, selectExpression); IEnumerable <OrderExpression> enumerable2 = from ob in selectExpression.OrderBy select new OrderExpression((ob.OrderType == OrderType.Ascending) ? OrderType.Descending : OrderType.Ascending, ob.Expression); selectExpression = selectExpression.SetOrderBy(enumerable2); selectExpression = selectExpression.SetTake(null); } return(selectExpression); }