internal static bool ShouldBeOptional(this EntityConstrain constrain, IEnumerable <IQueryComponentNavigator> currentQueryComponentStack)
        {
            bool result = false;

            foreach (IQueryComponentNavigator navigator in currentQueryComponentStack)
            {
                if ((navigator.NavigatedComponent is BinaryOperator) && (((BinaryOperator)navigator.NavigatedComponent).Member == MethodNames.Or))
                {
                    result = true;
                    break;
                }
            }

            return(result);
        }
 /// <summary>Visit an entity constrain.</summary>
 /// <param name="entityConstrain">Entity constrain to be visited.</param>
 protected override void VisitEntityConstrain(EntityConstrain entityConstrain)
 {
     int startIndex = _commandText.Length;
     VisitComponent(_currentEntityAccessor.Peek().About);
     _commandText.Append(" ");
     VisitComponent(entityConstrain.Predicate);
     _commandText.Append(" ");
     VisitComponent(entityConstrain.Value);
     _commandText.Append(" . ");
     int length = _commandText.Length - startIndex;
     if (!_visitedComponents.Contains(entityConstrain))
     {
         _visitedComponents.Add(entityConstrain, startIndex, length);
     }
 }
 /// <summary>Visit an entity constrain.</summary>
 /// <param name="entityConstrain">Entity constrain to be visited.</param>
 protected abstract void VisitEntityConstrain(EntityConstrain entityConstrain);
 /// <summary>Creates an instance of the conditional constrain selector.</summary>
 /// <param name="entityAccessor">Target entity accessor to wrap around.</param>
 /// <param name="entityConstrain">Entity constrain.</param>
 /// <param name="fallbackConstrain">Fallback constrain.</param>
 public ConditionalConstrainSelector(StrongEntityAccessor entityAccessor, EntityConstrain entityConstrain, EntityConstrain fallbackConstrain)
 {
     EntityAccessor    = entityAccessor;
     EntityConstrain   = entityConstrain;
     FallbackConstrain = fallbackConstrain;
 }
        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."));
            }
        }