コード例 #1
0
ファイル: SqlOuterApplyReducer.cs プロジェクト: zyj0021/ALinq
            private SqlJoin GetLeftOuterWithUnreferencedSingletonOnLeft(SqlSource source)
            {
                SqlAlias alias = source as SqlAlias;

                if (alias != null)
                {
                    SqlSelect node = alias.Node as SqlSelect;
                    if ((((node != null) && (node.Where == null)) && ((node.Top == null) && (node.GroupBy.Count == 0))) &&
                        (node.OrderBy.Count == 0))
                    {
                        return(this.GetLeftOuterWithUnreferencedSingletonOnLeft(node.From));
                    }
                }
                SqlJoin join = source as SqlJoin;

                if ((join == null) || (join.JoinType != SqlJoinType.LeftOuter))
                {
                    return(null);
                }
                if (!this.IsSingletonSelect(join.Left))
                {
                    return(null);
                }
                Dictionary <SqlAlias, bool> dictionary = SqlGatherProducedAliases.Gather(join.Left);

                foreach (SqlAlias alias2 in SqlGatherConsumedAliases.Gather(join.Right).Keys)
                {
                    if (dictionary.ContainsKey(alias2))
                    {
                        return(null);
                    }
                }
                return(join);
            }
コード例 #2
0
            // Methods
            internal override SqlSource VisitJoin(SqlJoin join)
            {
                if (join.JoinType != SqlJoinType.CrossApply)
                {
                    return(base.VisitJoin(join));
                }
                Dictionary <SqlAlias, bool> dictionary = SqlGatherProducedAliases.Gather(join.Left);

                foreach (SqlAlias alias in SqlGatherConsumedAliases.Gather(join.Right).Keys)
                {
                    if (dictionary.ContainsKey(alias))
                    {
                        this.Annotations.Add(join,
                                             new SqlServerCompatibilityAnnotation(
                                                 Strings.SourceExpressionAnnotation(join.SourceExpression),
                                                 new SqlProvider.ProviderMode[] { SqlProvider.ProviderMode.Sql2000 }));
                        return(base.VisitJoin(join));
                    }
                }
                join.JoinType = SqlJoinType.Cross;
                return(this.VisitJoin(join));
            }
コード例 #3
0
            internal override SqlSource VisitJoin(SqlJoin join)
            {
                if (join.JoinType != SqlJoinType.CrossApply)
                {
                    return(base.VisitJoin(join));
                }
                join.Left      = this.VisitSource(join.Left);
                join.Condition = this.VisitExpression(join.Condition);
                SelectScope expressionSink = this.expressionSink;

                this.expressionSink = new SelectScope();
                this.expressionSink.LeftProduction = SqlGatherProducedAliases.Gather(join.Left).Keys;
                join.Right = this.VisitSource(join.Right);
                SqlSource sqlSource = join;

                foreach (List <SqlColumn> list in this.expressionSink.Lifted)
                {
                    sqlSource = this.PushSourceDown(sqlSource, list);
                }
                this.expressionSink = expressionSink;
                return(sqlSource);
            }
コード例 #4
0
ファイル: SqlOuterApplyReducer.cs プロジェクト: zyj0021/ALinq
            internal override SqlSource VisitSource(SqlSource source)
            {
                source = base.VisitSource(source);
                SqlJoin node = source as SqlJoin;

                if (node != null)
                {
                    if (node.JoinType == SqlJoinType.OuterApply)
                    {
                        Dictionary <SqlAlias, bool>      aliasesForLifting = SqlGatherProducedAliases.Gather(node.Left);
                        Dictionary <SqlExpression, bool> liftedExpressions = new Dictionary <SqlExpression, bool>();
                        if (
                            (SqlOuterApplyReducer.SqlPredicateLifter.CanLift(node.Right, aliasesForLifting,
                                                                             liftedExpressions) &&
                             SqlOuterApplyReducer.SqlSelectionLifter.CanLift(node.Right, aliasesForLifting,
                                                                             liftedExpressions)) &&
                            !SqlOuterApplyReducer.SqlAliasDependencyChecker.IsDependent(node.Right, aliasesForLifting,
                                                                                        liftedExpressions))
                        {
                            SqlExpression expression = SqlOuterApplyReducer.SqlPredicateLifter.Lift(node.Right,
                                                                                                    aliasesForLifting);
                            List <List <SqlColumn> > list = SqlOuterApplyReducer.SqlSelectionLifter.Lift(node.Right,
                                                                                                         aliasesForLifting,
                                                                                                         liftedExpressions);
                            node.JoinType  = SqlJoinType.LeftOuter;
                            node.Condition = expression;
                            if (list != null)
                            {
                                foreach (List <SqlColumn> list2 in list)
                                {
                                    source = this.PushSourceDown(source, list2);
                                }
                            }
                        }
                        else
                        {
                            this.AnnotateSqlIncompatibility(node,
                                                            new SqlProvider.ProviderMode[]
                                                            { SqlProvider.ProviderMode.Sql2000 });
                        }
                    }
                    else if (node.JoinType == SqlJoinType.CrossApply)
                    {
                        SqlJoin leftOuterWithUnreferencedSingletonOnLeft =
                            this.GetLeftOuterWithUnreferencedSingletonOnLeft(node.Right);
                        if (leftOuterWithUnreferencedSingletonOnLeft != null)
                        {
                            Dictionary <SqlAlias, bool>      dictionary3 = SqlGatherProducedAliases.Gather(node.Left);
                            Dictionary <SqlExpression, bool> dictionary4 = new Dictionary <SqlExpression, bool>();
                            if (
                                (SqlOuterApplyReducer.SqlPredicateLifter.CanLift(
                                     leftOuterWithUnreferencedSingletonOnLeft.Right, dictionary3, dictionary4) &&
                                 SqlOuterApplyReducer.SqlSelectionLifter.CanLift(
                                     leftOuterWithUnreferencedSingletonOnLeft.Right, dictionary3, dictionary4)) &&
                                !SqlOuterApplyReducer.SqlAliasDependencyChecker.IsDependent(
                                    leftOuterWithUnreferencedSingletonOnLeft.Right, dictionary3, dictionary4))
                            {
                                SqlExpression right =
                                    SqlOuterApplyReducer.SqlPredicateLifter.Lift(
                                        leftOuterWithUnreferencedSingletonOnLeft.Right, dictionary3);
                                List <List <SqlColumn> > selections =
                                    SqlOuterApplyReducer.SqlSelectionLifter.Lift(
                                        leftOuterWithUnreferencedSingletonOnLeft.Right, dictionary3, dictionary4);
                                this.GetSelectionsBeforeJoin(node.Right, selections);
                                foreach (
                                    List <SqlColumn> list4 in
                                    selections.Where <List <SqlColumn> >(
                                        delegate(List <SqlColumn> s) { return(s.Count > 0); }))
                                {
                                    source = this.PushSourceDown(source, list4);
                                }
                                node.JoinType  = SqlJoinType.LeftOuter;
                                node.Condition =
                                    this.factory.AndAccumulate(leftOuterWithUnreferencedSingletonOnLeft.Condition, right);
                                node.Right = leftOuterWithUnreferencedSingletonOnLeft.Right;
                            }
                            else
                            {
                                this.AnnotateSqlIncompatibility(node,
                                                                new SqlProvider.ProviderMode[]
                                                                { SqlProvider.ProviderMode.Sql2000 });
                            }
                        }
                    }
                    while (node.JoinType == SqlJoinType.LeftOuter)
                    {
                        SqlJoin join3 = this.GetLeftOuterWithUnreferencedSingletonOnLeft(node.Left);
                        if (join3 == null)
                        {
                            return(source);
                        }
                        List <List <SqlColumn> > list5 = new List <List <SqlColumn> >();
                        this.GetSelectionsBeforeJoin(node.Left, list5);
                        foreach (List <SqlColumn> list6 in list5)
                        {
                            source = this.PushSourceDown(source, list6);
                        }
                        SqlSource     source2   = node.Right;
                        SqlExpression condition = node.Condition;
                        node.Left       = join3.Left;
                        node.Right      = join3;
                        node.Condition  = join3.Condition;
                        join3.Left      = join3.Right;
                        join3.Right     = source2;
                        join3.Condition = condition;
                    }
                }
                return(source);
            }