/// <summary>Visit a filter.</summary>
        /// <param name="filter">Filter to be visited.</param>
        protected override void VisitFilter(Filter filter)
        {
            int startIndex = _commandText.Length;
            _commandText.Append("FILTER (");
            VisitComponent(filter.Expression);
            _commandText.Append(") ");
            int length = _commandText.Length - startIndex;
            if (_cancelLast)
            {
                _commandText.Remove(startIndex, length);
            }

            _cancelLast = false;
        }
        private void VisitContainsResultOperator(ContainsResultOperator containsResultOperator, Remotion.Linq.QueryModel queryModel, int index)
        {
            if (_query.IsSubQuery)
            {
                _visitor.VisitExpression(containsResultOperator.Item);
                QueryComponent item = _visitor.RetrieveComponent();
                if (item is IExpression)
                {
                    Filter filter = new Filter(new BinaryOperator(MethodNames.Equal, _mainFromComponent.About, (IExpression)item));
                    if (!_mainFromComponent.Elements.Contains(filter))
                    {
                        _mainFromComponent.Elements.Add(filter);
                    }
                }

                EntityConstrain constrain = new EntityConstrain(
                    new Identifier(_mainFromComponent.About.Name + "_p"),
                    new Identifier(_mainFromComponent.About.Name + "_o"),
                    containsResultOperator.Item);
                if (!_mainFromComponent.Elements.Contains(constrain))
                {
                    _mainFromComponent.Elements.Add(constrain);
                }

                Call call = new Call(MethodNames.Any);
                call.Arguments.Add(_query);
                _result = call;
            }
            else
            {
                throw new NotSupportedException(System.String.Format("Cannot perform 'Contains' operation on top level query."));
            }
        }
 /// <summary>Visit a filter.</summary>
 /// <param name="filter">Filter to be visited.</param>
 protected abstract void VisitFilter(Filter filter);
        /// <summary>Visits a where clause.</summary>
        /// <param name="whereClause">Where clause to be visited.</param>
        /// <param name="queryModel">Query model containing given from clause.</param>
        /// <param name="index">Index of the where clause in the query model.</param>
        public override void VisitWhereClause(WhereClause whereClause, Remotion.Linq.QueryModel queryModel, int index)
        {
            _visitor.ConstantFromClause = _auxFromComponent;
            _visitor.VisitExpression(whereClause.Predicate);
            QueryComponent queryComponent = _visitor.RetrieveComponent();
            IQueryComponentNavigator queryComponentNavigator = queryComponent.GetQueryComponentNavigator();
            if (queryComponentNavigator != null)
            {
                queryComponentNavigator.ReplaceComponent(Identifier.Current, _subject);
            }

            if (queryComponent is QueryElement)
            {
                if ((!(queryComponent is EntityConstrain)) && (!_query.Elements.Contains((QueryElement)queryComponent)))
                {
                    _query.Elements.Add((QueryElement)queryComponent);
                }
            }
            else if (!_mainFromComponent.Elements.Contains(queryComponent))
            {
                Filter filter = new Filter((IExpression)queryComponent);
                if (!_mainFromComponent.Elements.Contains(filter))
                {
                    _mainFromComponent.Elements.Add(filter);
                }
            }

            base.VisitWhereClause(whereClause, queryModel, index);
        }