Exemplo n.º 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._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);
        }
Exemplo n.º 2
0
        protected override DbExpression VisitParameter(ParameterExpression exp)
        {
            //只支持 MappingFieldExpression 类型,即类似 q.Select(a=> a.Id).Where(a=> a > 0) 这种情况,也就是 ParameterExpression.Type 为基本映射类型。

            if (MappingTypeSystem.IsMappingType(exp.Type))
            {
                IObjectModel         model       = this.FindModel(exp);
                PrimitiveObjectModel resultModel = (PrimitiveObjectModel)model;
                return(resultModel.Expression);
            }
            else
            {
                throw new NotSupportedException(exp.ToString());
            }
        }