示例#1
0
        protected override Expression VisitSelect(SelectExpression node)
        {
            // visit column projection first
            ReadOnlyCollection<ColumnDeclaration> columns = node.Columns;

            List<ColumnDeclaration> alternate = null;
            for (Int32 i = 0, n = node.Columns.Count; i < n; i++)
            {
                ColumnDeclaration decl = node.Columns[i];
                if (IsColumnUsed(node.Alias, decl.Name))
                {
                    Expression expr = Visit(decl.Expression);
                    if (expr != decl.Expression)
                    {
                        decl = new ColumnDeclaration(decl.Name, expr);
                    }
                }
                else
                {
                    decl = null; // null means it gets omitted
                }
                if (decl != node.Columns[i] && alternate == null)
                {
                    alternate = new List<ColumnDeclaration>();
                    for (Int32 j = 0; j < i; j++)
                    {
                        alternate.Add(node.Columns[j]);
                    }
                }
                if (decl != null && alternate != null)
                {
                    alternate.Add(decl);
                }
            }
            if (alternate != null)
            {
                columns = alternate.AsReadOnly();
            }

            Expression take = Visit(node.Take);
            ReadOnlyCollection<Expression> groupbys = VisitExpressionList(node.GroupBy);
            ReadOnlyCollection<OrderByExpression> orderbys = VisitOrderBy(node.OrderBy);
            Expression where = Visit(node.Where);
            Expression from = Visit(node.From);

            ClearColumnsUsed(node.Alias);

            if (columns != node.Columns
                || take != node.Take
                || orderbys != node.OrderBy
                || groupbys != node.GroupBy
                || where != node.Where
                || from != node.From)
            {
                node = new SelectExpression(node.Alias, columns, from, where, orderbys, groupbys, take);
            }

            return node;
        }
示例#2
0
 // protected override methods
 protected override Expression VisitSelect(SelectExpression node)
 {
     node = (SelectExpression) base.VisitSelect(node);
     if (_lookup.Contains(node.Alias))
     {
         var aggColumns = new List<ColumnDeclaration>(node.Columns);
         foreach (AggregateSubqueryExpression ae in _lookup[node.Alias])
         {
             String name = "agg" + aggColumns.Count;
             var cd = new ColumnDeclaration(name, ae.AggregateInGroupSelect);
             _map.Add(ae, new ColumnExpression(ae.Type, ae.GroupByAlias, name));
             aggColumns.Add(cd);
         }
         return new SelectExpression(node.Alias, aggColumns, node.From, node.Where, node.OrderBy, node.GroupBy,
                                     node.Take);
     }
     return node;
 }