Beispiel #1
0
        public virtual IQueryState Accept(AggregateQueryExpression exp)
        {
            List <DbExpression> dbArguments = new List <DbExpression>(exp.Arguments.Count);

            foreach (Expression argument in exp.Arguments)
            {
                var arg = (LambdaExpression)argument;
                ScopeParameterDictionary scopeParameters = this._resultElement.ScopeParameters.Clone(arg.Parameters[0], this._resultElement.MappingObjectExpression);

                var dbArgument = GeneralExpressionParser.Parse(arg, scopeParameters, this._resultElement.ScopeTables);
                dbArguments.Add(dbArgument);
            }

            DbAggregateExpression  dbAggregateExp = new DbAggregateExpression(exp.ElementType, exp.Method, dbArguments);
            MappingFieldExpression mfe            = new MappingFieldExpression(exp.ElementType, dbAggregateExp);

            ResultElement result = new ResultElement(this._resultElement.ScopeParameters, this._resultElement.ScopeTables);

            result.MappingObjectExpression = mfe;
            result.FromTable = this._resultElement.FromTable;
            result.AppendCondition(this._resultElement.Condition);

            AggregateQueryState state = new AggregateQueryState(result);

            return(state);
        }
Beispiel #2
0
        public virtual IQueryState Accept(AggregateQueryExpression exp)
        {
            List <DbExpression> dbArguments = new List <DbExpression>(exp.Arguments.Count);

            foreach (Expression argument in exp.Arguments)
            {
                var arg = (LambdaExpression)argument;
                ScopeParameterDictionary scopeParameters = this._queryModel.ScopeParameters.Clone(arg.Parameters[0], this._queryModel.ResultModel);

                var dbArgument = GeneralExpressionParser.Parse(arg, scopeParameters, this._queryModel.ScopeTables);
                dbArguments.Add(dbArgument);
            }

            DbAggregateExpression dbAggregateExp = new DbAggregateExpression(exp.ElementType, exp.Method, dbArguments);
            PrimitiveObjectModel  resultModel    = new PrimitiveObjectModel(exp.ElementType, dbAggregateExp);

            QueryModel queryModel = new QueryModel(this._queryModel.ScopeParameters, this._queryModel.ScopeTables, this._queryModel.IgnoreFilters);

            queryModel.ResultModel = resultModel;
            queryModel.FromTable   = this._queryModel.FromTable;
            queryModel.AppendCondition(this._queryModel.Condition);

            AggregateQueryState state = new AggregateQueryState(queryModel);

            return(state);
        }
Beispiel #3
0
        public override JoinQueryResult ToJoinQueryResult(JoinType joinType, LambdaExpression conditionExpression, ScopeParameterDictionary scopeParameters, StringSet scopeTables, Func <string, string> tableAliasGenerator)
        {
            scopeParameters = scopeParameters.Clone(conditionExpression.Parameters.Last(), this.QueryModel.ResultModel);
            DbExpression          condition = GeneralExpressionParser.Parse(conditionExpression, scopeParameters, scopeTables);
            DbJoinTableExpression joinTable = new DbJoinTableExpression(joinType.AsDbJoinType(), this.QueryModel.FromTable.Table, condition);

            if (!this.QueryModel.IgnoreFilters)
            {
                joinTable.Condition = joinTable.Condition.And(this.QueryModel.ContextFilters).And(this.QueryModel.GlobalFilters);
            }

            JoinQueryResult result = new JoinQueryResult();

            result.ResultModel = this.QueryModel.ResultModel;
            result.JoinTable   = joinTable;

            return(result);
        }
Beispiel #4
0
        public virtual IQueryState Accept(GroupingQueryExpression exp)
        {
            foreach (LambdaExpression item in exp.GroupKeySelectors)
            {
                var keySelector = (LambdaExpression)item;
                ScopeParameterDictionary scopeParameters = this._queryModel.ScopeParameters.Clone(keySelector.Parameters[0], this._queryModel.ResultModel);

                this._queryModel.GroupSegments.AddRange(GroupKeySelectorParser.Parse(keySelector, scopeParameters, this._queryModel.ScopeTables));
            }

            foreach (LambdaExpression havingPredicate in exp.HavingPredicates)
            {
                ScopeParameterDictionary scopeParameters = this._queryModel.ScopeParameters.Clone(havingPredicate.Parameters[0], this._queryModel.ResultModel);

                var havingCondition = FilterPredicateParser.Parse(havingPredicate, scopeParameters, this._queryModel.ScopeTables);
                this._queryModel.AppendHavingCondition(havingCondition);
            }

            if (exp.Orderings.Count > 0)
            {
                this._queryModel.Orderings.Clear();
                this._queryModel.InheritOrderings = false;

                for (int i = 0; i < exp.Orderings.Count; i++)
                {
                    GroupingQueryOrdering groupOrdering = exp.Orderings[i];

                    ScopeParameterDictionary scopeParameters = this._queryModel.ScopeParameters.Clone(groupOrdering.KeySelector.Parameters[0], this._queryModel.ResultModel);

                    DbExpression orderingDbExp = GeneralExpressionParser.Parse(groupOrdering.KeySelector, scopeParameters, this._queryModel.ScopeTables);

                    DbOrdering ordering = new DbOrdering(orderingDbExp, groupOrdering.OrderType);
                    this._queryModel.Orderings.Add(ordering);
                }
            }

            QueryModel newQueryModel = this.CreateNewQueryModel(exp.Selector);

            return(new GroupingQueryState(newQueryModel));
        }
Beispiel #5
0
        public virtual JoinQueryResult ToJoinQueryResult(JoinType joinType, LambdaExpression conditionExpression, ScopeParameterDictionary scopeParameters, KeyDictionary <string> scopeTables, string tableAlias)
        {
            DbSqlQueryExpression sqlQuery = this.CreateSqlQuery();
            DbSubQueryExpression subQuery = new DbSubQueryExpression(sqlQuery);

            string         alias    = tableAlias;
            DbTableSegment tableSeg = new DbTableSegment(subQuery, alias, LockType.Unspecified);

            DbTable table = new DbTable(tableSeg.Alias);
            IMappingObjectExpression newMoe = this.Result.MappingObjectExpression.ToNewObjectExpression(sqlQuery, table);

            scopeParameters[conditionExpression.Parameters[conditionExpression.Parameters.Count - 1]] = newMoe;

            DbExpression condition = GeneralExpressionParser.Parse(conditionExpression, scopeParameters, scopeTables);

            DbJoinTableExpression joinTable = new DbJoinTableExpression(joinType.AsDbJoinType(), tableSeg, condition);

            JoinQueryResult result = new JoinQueryResult();

            result.MappingObjectExpression = newMoe;
            result.JoinTable = joinTable;
            return(result);
        }
Beispiel #6
0
        public virtual JoinQueryResult ToJoinQueryResult(JoinType joinType, LambdaExpression conditionExpression, ScopeParameterDictionary scopeParameters, StringSet scopeTables, string tableAlias)
        {
            DbSqlQueryExpression sqlQuery = this.CreateSqlQuery();
            DbSubQueryExpression subQuery = new DbSubQueryExpression(sqlQuery);

            string                alias     = tableAlias;
            DbTableSegment        tableSeg  = new DbTableSegment(subQuery, alias, LockType.Unspecified);
            DbJoinTableExpression joinTable = new DbJoinTableExpression(joinType.AsDbJoinType(), tableSeg);

            DbTable      aliasTable = new DbTable(tableSeg.Alias);
            IObjectModel newModel   = this.QueryModel.ResultModel.ToNewObjectModel(sqlQuery, aliasTable, joinTable);

            scopeParameters[conditionExpression.Parameters[conditionExpression.Parameters.Count - 1]] = newModel;

            DbExpression condition = GeneralExpressionParser.Parse(conditionExpression, scopeParameters, scopeTables);

            joinTable.Condition = condition;

            JoinQueryResult result = new JoinQueryResult();

            result.ResultModel = newModel;
            result.JoinTable   = joinTable;
            return(result);
        }
Beispiel #7
0
        protected DbOrdering ParseOrderExpression(OrderExpression orderExp)
        {
            ScopeParameterDictionary scopeParameters = this._queryModel.ScopeParameters.Clone(orderExp.KeySelector.Parameters[0], this._queryModel.ResultModel);

            DbExpression dbExpression = GeneralExpressionParser.Parse(orderExp.KeySelector, scopeParameters, this._queryModel.ScopeTables);
            DbOrderType  orderType;

            if (orderExp.NodeType == QueryExpressionType.OrderBy || orderExp.NodeType == QueryExpressionType.ThenBy)
            {
                orderType = DbOrderType.Asc;
            }
            else if (orderExp.NodeType == QueryExpressionType.OrderByDesc || orderExp.NodeType == QueryExpressionType.ThenByDesc)
            {
                orderType = DbOrderType.Desc;
            }
            else
            {
                throw new NotSupportedException(orderExp.NodeType.ToString());
            }

            DbOrdering ordering = new DbOrdering(dbExpression, orderType);

            return(ordering);
        }