Пример #1
0
 protected BetweenExpression UpdateBetween(BetweenExpression between, Expression expression, Expression lower, Expression upper)
 {
     if (expression != between.Expression || lower != between.Lower || upper != between.Upper)
     {
         return(new BetweenExpression(expression, lower, upper));
     }
     return(between);
 }
Пример #2
0
        protected virtual Expression VisitBetween(BetweenExpression between)
        {
            var expr  = this.Visit(between.Expression);
            var lower = this.Visit(between.Lower);
            var upper = this.Visit(between.Upper);

            return(this.UpdateBetween(between, expr, lower, upper));
        }
Пример #3
0
        protected override Expression VisitSelect(SelectExpression select)
        {
            select = (SelectExpression)base.VisitSelect(select);
            if (select.Skip != null)
            {
                SelectExpression newSelect    = select.SetSkip(null).SetTake(null);
                bool             canAddColumn = !select.IsDistinct && (select.GroupBy == null || select.GroupBy.Count == 0);
                if (!canAddColumn)
                {
                    newSelect = newSelect.AddRedundantSelect(new TableAlias());
                }

                var colType = SqlType.Int32;
                newSelect = newSelect.AddColumn(new ColumnDeclaration(columnName, new RowNumberExpression(select.OrderBy), colType));

                // add layer for WHERE clause that references new rownum column
                newSelect = newSelect.AddRedundantSelect(new TableAlias());
                newSelect = newSelect.RemoveColumn(newSelect.Columns.Single(c => c.Name == columnName));

                var newAlias           = ((SelectExpression)newSelect.From).Alias;
                ColumnExpression rnCol = new ColumnExpression(typeof(int), colType, newAlias, columnName);
                Expression where;

                if (select.Take != null)
                {
                    where = new BetweenExpression(rnCol, Expression.Add(select.Skip, Expression.Constant(1)), Expression.Add(select.Skip, select.Take));
                }
                else
                {
                    where = rnCol.GreaterThan(select.Skip);
                }

                if (newSelect.Where != null)
                {
                    where = newSelect.Where.And(where);
                }

                newSelect = newSelect.SetWhere(where);

                select = newSelect;
            }

            return(select);
        }
Пример #4
0
 protected virtual bool CompareBetween(BetweenExpression a, BetweenExpression b)
 {
     return(this.Compare(a.Expression, b.Expression) &&
            this.Compare(a.Lower, b.Lower) &&
            this.Compare(a.Upper, b.Upper));
 }