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 override FromQueryResult ToFromQueryResult() { if (this.Result.Condition == null) { FromQueryResult result = new FromQueryResult(); result.FromTable = this.Result.FromTable; result.MappingObjectExpression = this.Result.MappingObjectExpression; return(result); } return(base.ToFromQueryResult()); }
public virtual FromQueryResult ToFromQueryResult() { DbSqlQueryExpression sqlQuery = this.CreateSqlQuery(); DbSubQueryExpression subQuery = new DbSubQueryExpression(sqlQuery); DbTableSegment tableSeg = new DbTableSegment(subQuery, UtilConstants.DefaultTableAlias); DbFromTableExpression fromTable = new DbFromTableExpression(tableSeg); DbTable table = new DbTable(tableSeg.Alias); IMappingObjectExpression newMoe = this.Result.MappingObjectExpression.ToNewObjectExpression(sqlQuery, table); FromQueryResult result = new FromQueryResult(); result.FromTable = fromTable; result.MappingObjectExpression = newMoe; return(result); }
public virtual FromQueryResult ToFromQueryResult() { DbSqlQueryExpression sqlQuery = this.CreateSqlQuery(); DbSubQueryExpression subQuery = new DbSubQueryExpression(sqlQuery); DbTableSegment tableSeg = new DbTableSegment(subQuery, ResultElement.DefaultTableAlias); DbFromTableExpression fromTable = new DbFromTableExpression(tableSeg); DbTable table = new DbTable(tableSeg.Alias); IMappingObjectExpression newMoe = this.Result.MappingObjectExpression.ToNewObjectExpression(sqlQuery, table); FromQueryResult result = new FromQueryResult(); result.FromTable = fromTable; result.MappingObjectExpression = newMoe; return result; }