Ejemplo n.º 1
0
        public override IQueryState Visit(JoinQueryExpression exp)
        {
            ResultElement resultElement = new ResultElement();

            IQueryState     qs = QueryExpressionVisitor.VisitQueryExpression(exp.PrevExpression);
            FromQueryResult fromQueryResult = qs.ToFromQueryResult();

            DbFromTableExpression fromTable = fromQueryResult.FromTable;

            resultElement.FromTable = fromTable;

            List <IMappingObjectExpression> moeList = new List <IMappingObjectExpression>();

            moeList.Add(fromQueryResult.MappingObjectExpression);

            foreach (JoiningQueryInfo joiningQueryInfo in exp.JoinedQueries)
            {
                JoinQueryResult joinQueryResult = JoinQueryExpressionVisitor.VisitQueryExpression(joiningQueryInfo.Query.QueryExpression, resultElement, joiningQueryInfo.JoinType, joiningQueryInfo.Condition, moeList);

                var nullChecking = DbExpression.CaseWhen(new DbCaseWhenExpression.WhenThenExpressionPair(joinQueryResult.JoinTable.Condition, DbConstantExpression.One), DbConstantExpression.Null, DbConstantExpression.One.Type);

                if (joiningQueryInfo.JoinType == JoinType.LeftJoin)
                {
                    joinQueryResult.MappingObjectExpression.SetNullChecking(nullChecking);
                }
                else if (joiningQueryInfo.JoinType == JoinType.RightJoin)
                {
                    foreach (IMappingObjectExpression item in moeList)
                    {
                        item.SetNullChecking(nullChecking);
                    }
                }
                else if (joiningQueryInfo.JoinType == JoinType.FullJoin)
                {
                    joinQueryResult.MappingObjectExpression.SetNullChecking(nullChecking);
                    foreach (IMappingObjectExpression item in moeList)
                    {
                        item.SetNullChecking(nullChecking);
                    }
                }

                fromTable.JoinTables.Add(joinQueryResult.JoinTable);
                moeList.Add(joinQueryResult.MappingObjectExpression);
            }

            IMappingObjectExpression moe = SelectorExpressionVisitor.ResolveSelectorExpression(exp.Selector, moeList);

            resultElement.MappingObjectExpression = moe;

            GeneralQueryState queryState = new GeneralQueryState(resultElement);

            return(queryState);
        }
Ejemplo n.º 2
0
        public override IQueryState Visit(JoinQueryExpression exp)
        {
            IQueryState qs = QueryExpressionVisitor.VisitQueryExpression(exp.PrevExpression, this._scopeParameters, this._scopeTables);

            ResultElement resultElement = qs.ToFromQueryResult();

            List <IMappingObjectExpression> moeList = new List <IMappingObjectExpression>();

            moeList.Add(resultElement.MappingObjectExpression);

            foreach (JoiningQueryInfo joiningQueryInfo in exp.JoinedQueries)
            {
                ScopeParameterDictionary scopeParameters = resultElement.ScopeParameters.Clone(resultElement.ScopeParameters.Count + moeList.Count);
                for (int i = 0; i < moeList.Count; i++)
                {
                    ParameterExpression p = joiningQueryInfo.Condition.Parameters[i];
                    scopeParameters[p] = moeList[i];
                }

                JoinQueryResult joinQueryResult = JoinQueryExpressionVisitor.VisitQueryExpression(joiningQueryInfo.Query.QueryExpression, resultElement, joiningQueryInfo.JoinType, joiningQueryInfo.Condition, scopeParameters);

                var nullChecking = DbExpression.CaseWhen(new DbCaseWhenExpression.WhenThenExpressionPair(joinQueryResult.JoinTable.Condition, DbConstantExpression.One), DbConstantExpression.Null, DbConstantExpression.One.Type);

                if (joiningQueryInfo.JoinType == JoinType.LeftJoin)
                {
                    joinQueryResult.MappingObjectExpression.SetNullChecking(nullChecking);
                }
                else if (joiningQueryInfo.JoinType == JoinType.RightJoin)
                {
                    foreach (IMappingObjectExpression item in moeList)
                    {
                        item.SetNullChecking(nullChecking);
                    }
                }
                else if (joiningQueryInfo.JoinType == JoinType.FullJoin)
                {
                    joinQueryResult.MappingObjectExpression.SetNullChecking(nullChecking);
                    foreach (IMappingObjectExpression item in moeList)
                    {
                        item.SetNullChecking(nullChecking);
                    }
                }

                resultElement.FromTable.JoinTables.Add(joinQueryResult.JoinTable);
                moeList.Add(joinQueryResult.MappingObjectExpression);
            }

            ScopeParameterDictionary scopeParameters1 = resultElement.ScopeParameters.Clone(resultElement.ScopeParameters.Count + moeList.Count);

            for (int i = 0; i < moeList.Count; i++)
            {
                ParameterExpression p = exp.Selector.Parameters[i];
                scopeParameters1[p] = moeList[i];
            }
            IMappingObjectExpression moe = SelectorExpressionVisitor.ResolveSelectorExpression(exp.Selector, scopeParameters1, resultElement.ScopeTables);

            resultElement.MappingObjectExpression = moe;

            GeneralQueryState queryState = new GeneralQueryState(resultElement);

            return(queryState);
        }
Ejemplo n.º 3
0
        public static JoinQueryResult VisitQueryExpression(QueryExpression queryExpression, ResultElement resultElement, DbJoinType joinType, LambdaExpression conditionExpression, List <IMappingObjectExpression> moeList)
        {
            JoinQueryExpressionVisitor visitor = new JoinQueryExpressionVisitor(resultElement, joinType, conditionExpression, moeList);

            return(queryExpression.Accept(visitor));
        }
Ejemplo n.º 4
0
        public static JoinQueryResult VisitQueryExpression(QueryExpression queryExpression, ResultElement resultElement, JoinType joinType, LambdaExpression conditionExpression, ScopeParameterDictionary scopeParameters)
        {
            JoinQueryExpressionVisitor visitor = new JoinQueryExpressionVisitor(resultElement, joinType, conditionExpression, scopeParameters);

            return(queryExpression.Accept(visitor));
        }