public static ProjectedColumns ProjectColumns( Expression expression, IEnumerable<ColumnDeclaration> existingColumns, TableAlias newAlias, params TableAlias[] existingAliases) { return ProjectColumns(expression, existingColumns, newAlias, (IEnumerable<TableAlias>)existingAliases); }
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; }
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 }; }
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>(); } }
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 }; }
public TableExpression(TableAlias tableAlias, string tableName) : base(SqlExpressionType.Table, tableAlias) { this.TableName = tableName; }
public SelectExpression( TableAlias tableAlias, IEnumerable<ColumnDeclaration> columns, SqlExpression from, SqlExpression where ) : this(tableAlias, columns, from, where, null, null) { }
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) { }
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; }
public ColumnExpression(TableAlias tableAlias, string columnName) : base(SqlExpressionType.Column) { this.TableAlias = tableAlias; this.ColumnName = columnName; }
public AliasedExpression(SqlExpressionType nodeType, TableAlias tableAlias) : base(nodeType) { this.TableAlias = tableAlias; }