Ejemplo n.º 1
0
 protected override Expression VisitSelect(SelectExpression select)
 {
     sb.Append("SELECT ");
     for (int i = 0, n = select.Columns.Count; i < n; i++)
     {
         ColumnDeclaration column = select.Columns[i];
         if (i > 0)
         {
             sb.Append(", ");
         }
         ColumnExpression c = this.Visit(column.Expression) as ColumnExpression;
         if (c == null || c.Name != select.Columns[i].Name)
         {
             sb.Append(" AS ");
             sb.Append(column.Name);
         }
     }
     if (select.From != null)
     {
         this.AppendNewLine(Identation.Same);
         sb.Append("FROM ");
         this.VisitSource(select.From);
     }
     if (select.Where != null)
     {
         this.AppendNewLine(Identation.Same);
         sb.Append("WHERE ");
         this.Visit(select.Where);
     }
     return(select);
 }
Ejemplo n.º 2
0
        protected ReadOnlyCollection <ColumnDeclaration> VisitColumnDeclarations(ReadOnlyCollection <ColumnDeclaration> columns)
        {
            List <ColumnDeclaration> alternate = null;

            for (int i = 0, n = columns.Count; i < n; i++)
            {
                ColumnDeclaration column = columns[i];
                Expression        e      = this.Visit(column.Expression);
                if (alternate == null && e != column.Expression)
                {
                    alternate = columns.Take(i).ToList();
                }
                if (alternate != null)
                {
                    alternate.Add(new ColumnDeclaration(column.Name, e));
                }
            }
            if (alternate != null)
            {
                return(alternate.AsReadOnly());
            }
            return(columns);
        }