示例#1
0
        protected virtual Expression VisitBetween(BetweenExpression between)
        {
            Expression expr  = Visit(between.Expression);
            Expression lower = Visit(between.Lower);
            Expression upper = Visit(between.Upper);

            return(UpdateBetween(between, expr, lower, upper));
        }
示例#2
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);
 }
示例#3
0
 protected override Expression VisitBetween(BetweenExpression between)
 {
     VisitValue(between.Expression);
     Write(" BETWEEN ");
     VisitValue(between.Lower);
     Write(" AND ");
     VisitValue(between.Upper);
     return(between);
 }
示例#4
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(language, new TableAlias());
                }
                QueryType colType = language.TypeSystem.GetColumnType(typeof(int));
                newSelect = newSelect.AddColumn(new ColumnDeclaration("_rownum", new RowNumberExpression(select.OrderBy), colType));

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

                TableAlias newAlias = ((SelectExpression)newSelect.From).Alias;
                var        rnCol    = new ColumnExpression(typeof(int), colType, newAlias, "_rownum");
                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);
        }
示例#5
0
 protected virtual bool CompareBetween(BetweenExpression a, BetweenExpression b)
 {
     return(Compare(a.Expression, b.Expression) && Compare(a.Lower, b.Lower) && Compare(a.Upper, b.Upper));
 }