private void MapAliases(Expression a, Expression b) { TableAlias[] aliasArray = DeclaredAliasGatherer.Gather(a).ToArray <TableAlias>(); TableAlias[] aliasArray2 = DeclaredAliasGatherer.Gather(b).ToArray <TableAlias>(); int index = 0; int length = aliasArray.Length; while (index < length) { this.aliasScope.Add(aliasArray[index], aliasArray2[index]); index++; } }
private Expression MakeSubquery(Expression expression) { TableAlias alias = new TableAlias(); HashSet <TableAlias> set = DeclaredAliasGatherer.Gather(expression); List <ColumnDeclaration> columns = new List <ColumnDeclaration>(); foreach (TableAlias alias2 in set) { foreach (ColumnExpression expression2 in this.columns[alias2]) { ColumnDeclaration item = new ColumnDeclaration(columns.GetAvailableColumnName(expression2.Name), expression2, expression2.QueryType); columns.Add(item); ColumnExpression expression3 = new ColumnExpression(expression2.Type, expression2.QueryType, alias, expression2.Name); this.map.Add(expression2, expression3); } } return(new SelectExpression(alias, columns, expression, null)); }
public virtual Expression GetOuterJoinTest(SelectExpression select) { List <ColumnExpression> list = JoinColumnGatherer.Gather(DeclaredAliasGatherer.Gather(select.From), select).ToList <ColumnExpression>(); if (list.Count > 0) { foreach (ColumnExpression expression in list) { foreach (ColumnDeclaration declaration in select.Columns) { if (expression.Equals(declaration.Expression)) { return(expression); } } } return(list[0]); } return(Expression.Constant(1, typeof(int?))); }
protected override Expression VisitJoin(JoinExpression join) { join = (JoinExpression)base.VisitJoin(join); if ((join.Join == JoinType.CrossApply) || (join.Join == JoinType.OuterApply)) { if (join.Right is TableExpression) { return(new JoinExpression(JoinType.CrossJoin, join.Left, join.Right, null)); } SelectExpression right = join.Right as SelectExpression; if ((((right != null) && (right.Take == null)) && ((right.Skip == null) && !AggregateChecker.HasAggregates(right))) && ((right.GroupBy == null) || (right.GroupBy.Count == 0))) { SelectExpression source = right.SetWhere(null); HashSet <TableAlias> set = ReferencedAliasGatherer.Gather(source); HashSet <TableAlias> other = DeclaredAliasGatherer.Gather(join.Left); set.IntersectWith(other); if (set.Count == 0) { Expression where = right.Where; right = source; ProjectedColumns columns = ColumnProjector.ProjectColumns(this.language, where, right.Columns, right.Alias, DeclaredAliasGatherer.Gather(right.From)); right = right.SetColumns(columns.Columns); where = columns.Projector; return(new JoinExpression((where == null) ? JoinType.CrossJoin : ((join.Join == JoinType.CrossApply) ? JoinType.InnerJoin : JoinType.LeftOuter), join.Left, right, where)); } } } return(join); }