/// <summary>Visits a select clause.</summary> /// <param name="selectClause">Select clause to be visited.</param> /// <param name="queryModel">Query model containing given select clause.</param> public override void VisitSelectClause(SelectClause selectClause, Remotion.Linq.QueryModel queryModel) { queryModel.MainFromClause.Accept(this, queryModel); QuerySourceReferenceExpression querySource = FindQuerySource(selectClause.Selector); _visitor.Visit(selectClause.Selector); QueryComponent component = _visitor.RetrieveComponent(); _query = _visitor.Query; _mainFromComponent = _query.FindAllComponents <StrongEntityAccessor>().Where(item => item.SourceExpression == querySource.ReferencedQuerySource).First(); if (_query.Subject == null) { _query.Subject = _mainFromComponent.About; UnboundConstrain genericConstrain = new UnboundConstrain(new Identifier("s"), new Identifier("p"), new Identifier("o"), _mainFromComponent.SourceExpression.FromExpression); _mainFromComponent.Elements.Insert(0, genericConstrain); _mainFromComponent.UnboundGraphName = null; _query.Select.Add(genericConstrain); } _subject = _query.Subject; _query.Select.Add(_mainFromComponent); VisitBodyClauses(queryModel.BodyClauses, queryModel); VisitResultOperators(queryModel.ResultOperators, queryModel); OverrideSelector(component, selectClause.Selector); }
private void ProcessSelectableUnboundConstrain(UnboundConstrain expression, bool isSubQuery, Func <string, string> createVariableName, StrongEntityAccessor mainEntityAccessor) { if ((!isSubQuery) && (expression.Subject is Identifier) && (expression.Predicate is Identifier) && (expression.Value is Identifier)) { _subjectVariableName = ((Identifier)expression.Subject).Name; _predicateVariableName = ((Identifier)expression.Predicate).Name; _objectVariableName = ((Identifier)expression.Value).Name; } }
private void OverrideLiteralSelector(StrongEntityAccessor entityAccessor) { if (_mainFromComponent.Elements[0] is UnboundConstrain) { UnboundConstrain unboundConstrain = (UnboundConstrain)_mainFromComponent.Elements[0]; entityAccessor.Elements.Add(new Filter(new BinaryOperator(MethodNames.Equal, unboundConstrain.Subject, _mainFromComponent.About))); entityAccessor.Elements.Add(new Filter(new BinaryOperator(MethodNames.Equal, unboundConstrain.Predicate, new Literal(_propertyMapping.Uri)))); _query.Select.Add((Identifier)unboundConstrain.Subject); } }
/// <summary>Visit an unbound constrain.</summary> /// <param name="unboundConstrain">Unbound constrain to be visited.</param> protected override void VisitUnboundConstrain(UnboundConstrain unboundConstrain) { _commandText.Append(Indentation); VisitComponent(unboundConstrain.Subject); _commandText.Append(" "); VisitComponent(unboundConstrain.Predicate); _commandText.Append(" "); VisitComponent(unboundConstrain.Value); _commandText.Append(" . "); _commandText.AppendLine(); }
private void VisitCountResultOperator(CountResultOperator countResultOperator, Remotion.Linq.QueryModel queryModel, int index) { Call distinct = new Call(MethodNames.Distinct); distinct.Arguments.Add(_mainFromComponent.About); UnboundConstrain constrain = (UnboundConstrain)_mainFromComponent.Elements.FirstOrDefault(item => item.GetType() == typeof(UnboundConstrain)); if (constrain != null) { _mainFromComponent.Elements.Remove(constrain); } Call count = new Call(MethodNames.Count); count.Arguments.Add(distinct); _query.Select.Clear(); Alias alias = new Alias(count, new Identifier(_query.CreateVariableName(_query.RetrieveIdentifier(_mainFromComponent.About.Name) + "Count"), typeof(int))); _query.Select.Add(alias); }
private void OverrideEntitySelector(Identifier identifier) { StrongEntityAccessor entityAccessor = _query.FindAllComponents <StrongEntityAccessor>().Where(item => item.About == identifier).FirstOrDefault(); if (entityAccessor == null) { entityAccessor = new StrongEntityAccessor(identifier); _query.Elements.Add(entityAccessor); } if ((entityAccessor.UnboundGraphName == null) || (entityAccessor.UnboundGraphName == entityAccessor.About)) { entityAccessor.UnboundGraphName = (from accessor in _query.FindAllComponents <StrongEntityAccessor>() from constrain in accessor.Elements.OfType <EntityConstrain>() where (constrain.Value is Identifier) && ((Identifier)constrain.Value == identifier) select accessor.About).FirstOrDefault() ?? identifier; UnboundConstrain genericConstrain = new UnboundConstrain() { Subject = new Identifier(identifier.Name + "_s"), Predicate = new Identifier(identifier.Name + "_p"), Value = new Identifier(identifier.Name + "_o") }; entityAccessor.Elements.Add(genericConstrain); UnboundConstrain targetConstrain = new UnboundConstrain() { Subject = identifier, Predicate = new Identifier(identifier.Name + "p"), Value = new Identifier(identifier.Name + "o") }; entityAccessor.Elements.Add(targetConstrain); _query.Select.Clear(); if (_mainFromComponent.Elements[0] is UnboundConstrain) { ConditionalConstrainSelector selector = new ConditionalConstrainSelector(entityAccessor, genericConstrain, (UnboundConstrain)_mainFromComponent.Elements[0]); _query.Select.Add(selector); } _query.Select.Add(entityAccessor); } }
/// <summary>Visit an unbound constrain.</summary> /// <param name="unboundConstrain">Unbound constrain to be visited.</param> protected abstract void VisitUnboundConstrain(UnboundConstrain unboundConstrain);
/// <summary>Default constructor with nagivated unbound constrain.</summary> /// <param name="unboundConstrain">Nagivated unbound constrain.</param> internal UnboundConstrainNavigator(UnboundConstrain unboundConstrain) : base(unboundConstrain) { }
/// <summary>Default constructor with nagivated unbound constrain.</summary> /// <param name="unboundConstrain">Nagivated unbound constrain.</param> internal UnboundConstrainNavigator(UnboundConstrain unboundConstrain) : base(unboundConstrain) { }