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); }
public virtual ResultElement CreateNewResult(LambdaExpression selector) { ResultElement result = new ResultElement(); result.FromTable = this._resultElement.FromTable; IMappingObjectExpression r = SelectorExpressionVisitor.VisitSelectExpression(selector, this.MoeList); result.MappingObjectExpression = r; result.Orderings.AddRange(this._resultElement.Orderings); result.AppendCondition(this._resultElement.Condition); result.GroupSegments.AddRange(this._resultElement.GroupSegments); result.AppendHavingCondition(this._resultElement.HavingCondition); return(result); }
public virtual ResultElement CreateNewResult(LambdaExpression selector) { ResultElement result = new ResultElement(this._resultElement.ScopeParameters, this._resultElement.ScopeTables); result.FromTable = this._resultElement.FromTable; ScopeParameterDictionary scopeParameters = this._resultElement.ScopeParameters.Clone(selector.Parameters[0], this._resultElement.MappingObjectExpression); IMappingObjectExpression r = SelectorExpressionVisitor.ResolveSelectorExpression(selector, scopeParameters, this._resultElement.ScopeTables); result.MappingObjectExpression = r; result.Orderings.AddRange(this._resultElement.Orderings); result.AppendCondition(this._resultElement.Condition); result.GroupSegments.AddRange(this._resultElement.GroupSegments); result.AppendHavingCondition(this._resultElement.HavingCondition); return result; }
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); }