Ejemplo n.º 1
0
 public static ProjectedColumns ProjectColumns(
     Expression expression,
     IEnumerable<ColumnDeclaration> existingColumns,
     TableAlias newAlias,
     params TableAlias[] existingAliases)
 {
     return ProjectColumns(expression, existingColumns, newAlias, (IEnumerable<TableAlias>)existingAliases);
 }
Ejemplo n.º 2
0
 protected virtual string GetAliasName(TableAlias alias)
 {
     string name;
     if(!this.aliases.TryGetValue(alias, out name))
     {
         name = "t" + this.aliases.Count;
         this.aliases.Add(alias, name);
     }
     return name;
 }
Ejemplo n.º 3
0
 public static ProjectedColumns ProjectColumns(
     Expression expression, 
     IEnumerable<ColumnDeclaration> existingColumns, 
     TableAlias newAlias, 
     IEnumerable<TableAlias> existingAliases)
 {
     ColumnProjector projector = new ColumnProjector(existingColumns, newAlias, existingAliases);
     Expression expr = projector.Visit(expression);
     return new ProjectedColumns { Projector = expr, Columns = projector.columns };
 }
Ejemplo n.º 4
0
 private ColumnProjector(IEnumerable<ColumnDeclaration> existingColumns, TableAlias newAlias, IEnumerable<TableAlias> existingAliases)
 {
     this.newAlias = newAlias;
     this.existingAliases = new HashSet<TableAlias>(existingAliases);
     this.map = new Dictionary<ColumnExpression, ColumnExpression>();
     if(existingColumns != null)
     {
         this.columns = new List<ColumnDeclaration>(existingColumns);
     }
     else
     {
         this.columns = new List<ColumnDeclaration>();
     }
 }
Ejemplo n.º 5
0
 private BindResult RebindOrderings(IList<OrderByDeclaration> orderings, TableAlias alias, HashSet<TableAlias> existingAliases, IList<ColumnDeclaration> existingColumns)
 {
     List<ColumnDeclaration> newColumns = null;
     List<OrderByDeclaration> newOrderings = new List<OrderByDeclaration>();
     foreach(OrderByDeclaration ordering in orderings)
     {
         SqlExpression expr = ordering.Expression;
         ColumnExpression column = expr as ColumnExpression;
         if(column == null || existingAliases != null && existingAliases.Contains(column.TableAlias))
         {
             int ordinal = 0;
             foreach(ColumnDeclaration decl in existingColumns)
             {
                 ColumnExpression declColumn = decl.Expression as ColumnExpression;
                 if(decl.Expression == ordering.Expression || column != null && declColumn != null && column.TableAlias == declColumn.TableAlias && column.ColumnName == declColumn.ColumnName)
                 {
                     expr = new ColumnExpression(alias, decl.DeclaredName);
                     break;
                 }
                 ordinal++;
             }
             if(expr == ordering.Expression)
             {
                 if(newColumns == null)
                 {
                     newColumns = new List<ColumnDeclaration>(existingColumns);
                     existingColumns = newColumns;
                 }
                 string colName = column != null ? column.ColumnName : "c" + ordinal;
                 colName = GetAvailableColumnName(newColumns, colName);
                 newColumns.Add(new ColumnDeclaration(colName, ordering.Expression));
                 expr = new ColumnExpression(alias, colName);
             }
             newOrderings.Add(new OrderByDeclaration(ordering.OrderType, expr));
         }
     }
     return new BindResult() { Columns = existingColumns, Orderings = newOrderings };
 }
Ejemplo n.º 6
0
 public TableExpression(TableAlias tableAlias, string tableName)
     : base(SqlExpressionType.Table, tableAlias)
 {
     this.TableName = tableName;
 }
Ejemplo n.º 7
0
 public SelectExpression(
     TableAlias tableAlias,
     IEnumerable<ColumnDeclaration> columns,
     SqlExpression from,
     SqlExpression where
     )
     : this(tableAlias, columns, from, where, null, null)
 {
 }
Ejemplo n.º 8
0
 public SelectExpression(
     TableAlias tableAlias,
     IEnumerable<ColumnDeclaration> columns,
     SqlExpression from,
     SqlExpression where,
     IEnumerable<OrderByDeclaration> orderBy,
     IEnumerable<SqlExpression> groupBy
     )
     : this(tableAlias, columns, from, where, orderBy, groupBy, null, null, false)
 {
 }
Ejemplo n.º 9
0
 public SelectExpression(
     TableAlias tableAlias,
     IEnumerable<ColumnDeclaration> columns,
     SqlExpression from,
     SqlExpression where,
     IEnumerable<OrderByDeclaration> orderBy,
     IEnumerable<SqlExpression> groupBy,
     int? skip,
     int? take,
     bool isDistinct 
     )
     : base(SqlExpressionType.Select, tableAlias)
 {
     this.Columns = columns.ToReadOnly();
     this.From = from;
     this.Where = where;
     this.OrderBy = orderBy.ToReadOnly();
     this.GroupBy = groupBy.ToReadOnly();
     this.Skip = skip;
     this.Take = take;
     this.IsDistinct = isDistinct;
 }
Ejemplo n.º 10
0
 public ColumnExpression(TableAlias tableAlias, string columnName)
     : base(SqlExpressionType.Column)
 {
     this.TableAlias = tableAlias;
     this.ColumnName = columnName;
 }
Ejemplo n.º 11
0
 public AliasedExpression(SqlExpressionType nodeType, TableAlias tableAlias)
     : base(nodeType)
 {
     this.TableAlias = tableAlias;
 }