Beispiel #1
0
            public static HashSet <ColumnExpression> Gather(HashSet <TableAlias> aliases, SelectExpression select)
            {
                var gatherer = new JoinColumnGatherer(aliases);

                gatherer.Gather(select.Where);
                return(gatherer.columns);
            }
Beispiel #2
0
        protected override Expression VisitProjection(ProjectionExpression proj)
        {
            SelectExpression save = currentSelect;

            currentSelect = proj.Select;
            try {
                if (!isTopLevel)
                {
                    if (CanJoinOnClient(currentSelect))
                    {
                        // make a query that combines all the constraints from the outer queries into a single select
                        var newOuterSelect = (SelectExpression)QueryDuplicator.Duplicate(save);

                        // remap any references to the outer select to the new alias;
                        var newInnerSelect = (SelectExpression)ColumnMapper.Map(proj.Select, newOuterSelect.Alias, save.Alias);
                        // add outer-join test
                        ProjectionExpression newInnerProjection = language.AddOuterJoinTest(new ProjectionExpression(newInnerSelect, proj.Projector));
                        newInnerSelect = newInnerProjection.Select;
                        Expression newProjector = newInnerProjection.Projector;

                        var newAlias        = new TableAlias();
                        ProjectedColumns pc = ColumnProjector.ProjectColumns(language, newProjector, null, newAlias, newOuterSelect.Alias, newInnerSelect.Alias);

                        var join         = new JoinExpression(JoinType.OuterApply, newOuterSelect, newInnerSelect, null);
                        var joinedSelect = new SelectExpression(newAlias, pc.Columns, join, null, null, null, proj.IsSingleton, null, null, false);

                        // apply client-join treatment recursively
                        currentSelect = joinedSelect;
                        newProjector  = Visit(pc.Projector);

                        // compute keys (this only works if join condition was a single column comparison)
                        var outerKeys = new List <Expression>();
                        var innerKeys = new List <Expression>();
                        if (GetEquiJoinKeyExpressions(newInnerSelect.Where, newOuterSelect.Alias, outerKeys, innerKeys))
                        {
                            // outerKey needs to refer to the outer-scope's alias
                            IEnumerable <Expression> outerKey = outerKeys.Select(k => ColumnMapper.Map(k, save.Alias, newOuterSelect.Alias));
                            // innerKey needs to refer to the new alias for the select with the new join
                            IEnumerable <Expression> innerKey = innerKeys.Select(k => ColumnMapper.Map(k, joinedSelect.Alias, ((ColumnExpression)k).Alias));
                            var newProjection = new ProjectionExpression(joinedSelect, newProjector, proj.Aggregator);
                            return(new ClientJoinExpression(newProjection, outerKey, innerKey));
                        }
                    }
                    else
                    {
                        bool saveJoin = canJoinOnClient;
                        canJoinOnClient = false;
                        Expression result = base.VisitProjection(proj);
                        canJoinOnClient = saveJoin;
                        return(result);
                    }
                }
                else
                {
                    isTopLevel = false;
                }
                return(base.VisitProjection(proj));
            }
            finally {
                currentSelect = save;
            }
        }
Beispiel #3
0
 protected override Expression VisitSelect(SelectExpression select)
 {
     selects.Add(select);
     return(select); // don't visit sub-queries
 }
Beispiel #4
0
 private bool CanJoinOnClient(SelectExpression select)
 {
     // can add singleton (1:0,1) join if no grouping/aggregates or distinct
     return(canJoinOnClient && currentMember != null && !policy.IsDeferLoaded(currentMember) && !select.IsDistinct && (select.GroupBy == null || select.GroupBy.Count == 0) &&
            !AggregateChecker.HasAggregates(select));
 }
 protected override Expression VisitSelect(SelectExpression select)
 {
     aliases.Add(select.Alias);
     return(select);
 }