private void VisitContainsResultOperator(ContainsResultOperator containsResultOperator, Remotion.Linq.QueryModel queryModel, int index)
        {
            if (_query.IsSubQuery)
            {
                _visitor.Visit(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."));
            }
        }
Ejemplo n.º 2
0
        private System.Linq.Expressions.Expression VisitPredicateMethodCallUnsafe(System.Linq.Expressions.MethodCallExpression expression, Uri predicate, StrongEntityAccessor entityAccessor)
        {
            _query.AddEntityAccessor(entityAccessor);
            Identifier      memberIdentifier = new Identifier(_query.CreateVariableName(predicate.GetFragmentOrLastSegment()));
            EntityConstrain constrain        = new EntityConstrain();

            constrain.Predicate = new Literal(predicate);
            constrain.Value     = memberIdentifier;
            if (!entityAccessor.Elements.Contains(constrain))
            {
                entityAccessor.Elements.Add(constrain);
            }

            if (constrain.ShouldBeOptional(_currentComponent))
            {
                entityAccessor.Elements.Remove(constrain);
                OptionalPattern optional = new OptionalPattern();
                optional.Patterns.Add(constrain);
                entityAccessor.Elements.Add(optional);
            }

            HandleComponent(memberIdentifier);
            _lastComponent = memberIdentifier;
            return(expression);
        }
        /// <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;

            _commandText.Append(Indentation);
            VisitComponent(_currentEntityAccessor.Peek().About);
            _commandText.Append(" ");
            VisitComponent(entityConstrain.Predicate);
            _commandText.Append(" ");
            VisitComponent(entityConstrain.Value);
            _commandText.Append(" . ");
            _commandText.AppendLine();
            int length = _commandText.Length - startIndex;

            if (!_visitedComponents.Contains(entityConstrain))
            {
                _visitedComponents.Add(entityConstrain, startIndex, length);
            }
        }
Ejemplo n.º 4
0
        /// <summary>Visits an entity member.</summary>
        /// <param name="expression">Expression to be visited.</param>
        /// <returns>Expression visited</returns>
        protected virtual System.Linq.Expressions.Expression VisitEntityProperty(EntityPropertyExpression expression)
        {
            StrongEntityAccessor entityAccessor = this.GetEntityAccessor(expression.Target);

            _query.AddEntityAccessor(entityAccessor);
            Identifier      memberIdentifier = null;
            EntityConstrain constrain        = _query.FindAllComponents <EntityConstrain>()
                                               .FirstOrDefault(item => (item.GetType() == typeof(EntityConstrain) && (item.TargetExpression.EqualsTo(expression.Expression))));

            if (constrain == null)
            {
                memberIdentifier = (_query.FindAllComponents <StrongEntityAccessor>()
                                    .Where(item => item.SourceExpression.FromExpression.EqualsTo(expression.Expression))
                                    .Select(item => item.About).FirstOrDefault()) ?? (new Identifier(_query.CreateVariableName(expression.Name), expression.EntityProperty.PropertyType));
                constrain = new EntityConstrain(new Literal(expression.PropertyMapping.Uri), memberIdentifier, expression.Expression);
                if (!entityAccessor.Elements.Contains(constrain))
                {
                    entityAccessor.Elements.Add(constrain);
                }
            }
            else
            {
                if (constrain.ShouldBeOptional(_currentComponent))
                {
                    entityAccessor.Elements.Remove(constrain);
                    OptionalPattern optional = new OptionalPattern();
                    optional.Patterns.Add(constrain);
                    entityAccessor.Elements.Add(optional);
                }

                memberIdentifier = (Identifier)constrain.Value;
            }

            HandleComponent(memberIdentifier);
            _lastComponent = memberIdentifier;
            return(expression);
        }
 /// <summary>Default constructor with nagivated entity constrain.</summary>
 /// <param name="entityConstrain">Nagivated entity constrain.</param>
 internal EntityConstrainNavigator(EntityConstrain entityConstrain)
     : base(entityConstrain)
 {
 }
Ejemplo n.º 6
0
 /// <summary>Visit an entity constrain.</summary>
 /// <param name="entityConstrain">Entity constrain to be visited.</param>
 protected abstract void VisitEntityConstrain(EntityConstrain entityConstrain);
Ejemplo n.º 7
0
 /// <summary>Default constructor with nagivated entity constrain.</summary>
 /// <param name="entityConstrain">Nagivated entity constrain.</param>
 internal EntityConstrainNavigator(EntityConstrain entityConstrain)
     : base(entityConstrain)
 {
 }