示例#1
0
        /// <summary>Visits a sub-query expression.</summary>
        /// <param name="expression">Expression to be visited.</param>
        /// <returns>Expression visited</returns>
        protected override System.Linq.Expressions.Expression VisitSubQuery(SubQueryExpression expression)
        {
            Remotion.Linq.Clauses.FromClauseBase sourceExpression = (Remotion.Linq.Clauses.FromClauseBase)((QuerySourceReferenceExpression)expression.QueryModel.SelectClause.Selector).ReferencedQuerySource;
            StrongEntityAccessor entityAccessor = (sourceExpression.FromExpression is System.Linq.Expressions.ConstantExpression ? null : this.GetEntityAccessor(sourceExpression));

            if (entityAccessor != null)
            {
                Query query = _query.CreateSubQuery(entityAccessor.About);
                query.AddEntityAccessor(entityAccessor);
                EntityQueryModelVisitor queryModelVisitor = new EntityQueryModelVisitor(query, _entityContext);
                queryModelVisitor.VisitQueryModel(expression.QueryModel);
                _lastComponent = queryModelVisitor.Result;
                HandleComponent(_lastComponent);
            }
            else
            {
                NonEntityQueryModelVisitor       queryModelVisitor = new NonEntityQueryModelVisitor(this, ConstantFromClause);
                Stack <IQueryComponentNavigator> currentComponent  = _currentComponent;
                _currentComponent = new Stack <IQueryComponentNavigator>();
                queryModelVisitor.VisitQueryModel(expression.QueryModel);
                _currentComponent = currentComponent;
                _lastComponent    = queryModelVisitor.Result;
                HandleComponent(_lastComponent);
            }

            return(expression);
        }
 private Model.Query VisitQueryModel(QueryModel queryModel)
 {
     _modelVisitor = new EntityQueryModelVisitor(_entityContext);
     _modelVisitor.VisitQueryModel(queryModel);
     return(_queryOptimizer.Optimize(_modelVisitor.Query));
 }