Esempio n. 1
0
        /// <summary>
        /// Visits the main from clause.
        /// </summary>
        /// <param name="fromClause">From clause.</param>
        /// <param name="queryModel">The query model.</param>
        /// <remarks></remarks>
        public override void VisitMainFromClause(MainFromClause fromClause, Remotion.Linq.QueryModel queryModel)
        {
            var sourceAsConstant = queryModel.MainFromClause.FromExpression as ConstantExpression;

            if (sourceAsConstant != null)
            {
                _queryDescription.SetFromClause("", HierarchyScope.AllOrNone, FromClause.RevisionStatusNotSpecifiedType);
                // Tues 1 Nov: _queryDescription.SetResultFilterClause(fromClause.ItemType, ResultFilterType.Sequence, -1);
                _queryDescription.SetResultFilterClause(GetResultType(fromClause, queryModel), ResultFilterType.Sequence, -1);

                RunCustomModifiers(queryModel);
            }

            var sourceAsSubQuery = fromClause.FromExpression as SubQueryExpression;

            if (sourceAsSubQuery != null)
            {
                var subQueryModel = sourceAsSubQuery.QueryModel;
                RunCustomModifiers(subQueryModel);
            }

            // If the Where clause is null, we have a request for "get all", but the VisitWhereClause method never runs (thanks Remotion!)
            // so let's fake it here
            if (!queryModel.BodyClauses.Any())
            {
                queryModel.BodyClauses.Add(new WhereClause(Expression.Equal(IgnoreExpression, IgnoreExpression)));
            }

            base.VisitMainFromClause(fromClause, queryModel);
        }
Esempio n. 2
0
        /// <summary>
        /// Visits the main from clause.
        /// </summary>
        /// <param name="fromClause">From clause.</param>
        /// <param name="queryModel">The query model.</param>
        /// <remarks></remarks>
        public override void VisitMainFromClause(MainFromClause fromClause, Remotion.Linq.QueryModel queryModel)
        {
            var sourceAsConstant = queryModel.MainFromClause.FromExpression as ConstantExpression;

            if (sourceAsConstant != null)
            {
                _queryDescription.SetFromClause(HierarchyScope.Indeterminate, FromClause.RevisionStatusNotSpecifiedType);
                // Tues 1 Nov: _queryDescription.SetResultFilterClause(fromClause.ItemType, ResultFilterType.Sequence, -1);
                //_queryDescription.AddResultFilter(GetResultType(fromClause, queryModel), ResultFilterType.Sequence, -1);
            }
            RunCustomModifiers(queryModel);

            var sourceAsSubQuery = fromClause.FromExpression as SubQueryExpression;

            if (sourceAsSubQuery != null)
            {
                var subQueryModel = sourceAsSubQuery.QueryModel;
                RunCustomModifiers(subQueryModel);

                // When there is a query like "MyList.Skip(5).Count()" then "MyList.Skip(5)" is the MainFromClause
                // and it's represented as a SubQuery, with "Count()" being the single ResultOperator on the outer query
                // Since for our purposes we flatten this all because we don't support subqueries, then
                // go and visit the ResultOperators of the inner query to add them to our single QueryDescription's
                // ResultFilters list to make sure we catch both Skip and Count in this example.
                for (int index = 0; index < subQueryModel.ResultOperators.Count; index++)
                {
                    var resultOperator = subQueryModel.ResultOperators[index];
                    VisitResultOperator(resultOperator, sourceAsSubQuery.QueryModel, index);
                }
            }

            // If the Where clause is null, we have a request for "get all", but the VisitWhereClause method never runs (thanks Remotion!)
            // so let's fake it here
            if (!queryModel.BodyClauses.Any())
            {
                queryModel.BodyClauses.Add(new WhereClause(Expression.Equal(IgnoreExpression, IgnoreExpression)));
            }

            base.VisitMainFromClause(fromClause, queryModel);
        }