public virtual QueryModel CreateNewQueryModel(LambdaExpression selector) { QueryModel newQueryModel = this._queryModel.Clone(); ScopeParameterDictionary scopeParameters = this._queryModel.ScopeParameters.Clone(selector.Parameters[0], this._queryModel.ResultModel); IObjectModel newResultModel = SelectorResolver.Resolve(selector, scopeParameters, this._queryModel.ScopeTables); newQueryModel.ResultModel = newResultModel; return(newQueryModel); }
public virtual QueryModel CreateNewQueryModel(LambdaExpression selector) { QueryModel newQueryModel = this._queryModel.Clone(); ComplexObjectModel complexObjectModel = this._queryModel.ResultModel as ComplexObjectModel; if (complexObjectModel != null) { complexObjectModel.SetupFilters(this._queryModel.IgnoreFilters); } ScopeParameterDictionary scopeParameters = this._queryModel.ScopeParameters.Clone(selector.Parameters[0], this._queryModel.ResultModel); IObjectModel newResultModel = SelectorResolver.Resolve(selector, scopeParameters, this._queryModel.ScopeTables); newQueryModel.ResultModel = newResultModel; return(newQueryModel); }
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 = SelectorResolver.Resolve(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 = QueryExpressionResolver.Resolve(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 = JoinQueryExpressionResolver.Resolve(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 = SelectorResolver.Resolve(exp.Selector, scopeParameters1, resultElement.ScopeTables); resultElement.MappingObjectExpression = moe; GeneralQueryState queryState = new GeneralQueryState(resultElement); return(queryState); }
public override IQueryState Visit(JoinQueryExpression exp) { IQueryState qs = QueryExpressionResolver.Resolve(exp.PrevExpression, this._scopeParameters, this._scopeTables); QueryModel queryModel = qs.ToFromQueryModel(); List <IObjectModel> modelList = new List <IObjectModel>(); modelList.Add(queryModel.ResultModel); foreach (JoinQueryInfo joinQueryInfo in exp.JoinedQueries) { ScopeParameterDictionary scopeParameters = queryModel.ScopeParameters.Clone(queryModel.ScopeParameters.Count + modelList.Count); for (int i = 0; i < modelList.Count; i++) { ParameterExpression p = joinQueryInfo.Condition.Parameters[i]; scopeParameters[p] = modelList[i]; } JoinQueryResult joinQueryResult = JoinQueryExpressionResolver.Resolve(joinQueryInfo, queryModel, scopeParameters); var nullChecking = DbExpression.CaseWhen(new DbCaseWhenExpression.WhenThenExpressionPair(joinQueryResult.JoinTable.Condition, DbConstantExpression.One), DbConstantExpression.Null, DbConstantExpression.One.Type); if (joinQueryInfo.JoinType == JoinType.LeftJoin) { joinQueryResult.ResultModel.SetNullChecking(nullChecking); } else if (joinQueryInfo.JoinType == JoinType.RightJoin) { foreach (IObjectModel item in modelList) { item.SetNullChecking(nullChecking); } } else if (joinQueryInfo.JoinType == JoinType.FullJoin) { joinQueryResult.ResultModel.SetNullChecking(nullChecking); foreach (IObjectModel item in modelList) { item.SetNullChecking(nullChecking); } } queryModel.FromTable.JoinTables.Add(joinQueryResult.JoinTable); modelList.Add(joinQueryResult.ResultModel); } ScopeParameterDictionary scopeParameters1 = queryModel.ScopeParameters.Clone(queryModel.ScopeParameters.Count + modelList.Count); for (int i = 0; i < modelList.Count; i++) { ParameterExpression p = exp.Selector.Parameters[i]; scopeParameters1[p] = modelList[i]; } IObjectModel model = SelectorResolver.Resolve(exp.Selector, scopeParameters1, queryModel.ScopeTables); queryModel.ResultModel = model; GeneralQueryState queryState = new GeneralQueryState(queryModel); return(queryState); }