/// <summary>Constrctor with subject passed.</summary> /// <param name="subject">Subject of this query.</param> internal Query(Identifier subject) : base() { _queryForm = QueryForms.Select; ObservableCollection<Prefix> prefixes = new ObservableCollection<Prefix>(); prefixes.CollectionChanged += OnCollectionChanged; _prefixes = prefixes; ObservableCollection<ISelectableQueryComponent> select = new ObservableCollection<ISelectableQueryComponent>(); select.CollectionChanged += OnCollectionChanged; _select = select; ObservableCollection<QueryElement> elements = new ObservableCollection<QueryElement>(); elements.CollectionChanged += OnCollectionChanged; _elements = elements; _variableNamingStrategy = new UniqueVariableNamingStrategy(this); _variableNamingConvention = new CamelCaseVariableNamingConvention(); if ((_subject = subject) != null) { _subject.OwnerQuery = this; } }
/// <summary>Visit a identifier.</summary> /// <param name="identifier">Identifier to be visited.</param> protected override void VisitIdentifier(Identifier identifier) { _commandText.AppendFormat("?{0}", (_variableNameOverride.ContainsKey(identifier) ? _variableNameOverride[identifier] : identifier.Name)); }
/// <summary>Default constructor with aboutness and its source passed.</summary> /// <param name="about">Specifies an entity identifier given accesor uses.</param> /// <param name="sourceExpression">Source of this entity accessor.</param> /// <param name="entityAccessor">Strong entity accessor.</param> internal UnspecifiedEntityAccessor(Identifier about, Remotion.Linq.Clauses.FromClauseBase sourceExpression, StrongEntityAccessor entityAccessor) : base(about, sourceExpression) { _entityAccessor = entityAccessor; }
/// <summary>Default constructor with aboutness assuming that a source is a variable.</summary> /// <param name="about">Points to the primary topic of given entity accessor.</param> /// <param name="entityAccessor">Strong entity accessor.</param> internal UnspecifiedEntityAccessor(Identifier about, StrongEntityAccessor entityAccessor) : base(about) { _entityAccessor = entityAccessor; }
/// <summary>Constructor with subject and variable naming strategy passed.</summary> /// <param name="subject">Subject of this query.</param> /// <param name="variableNamingStrategy">Varialbe naming strategy.</param> internal Query(Identifier subject, IVariableNamingStrategy variableNamingStrategy) : this(subject) { _variableNamingStrategy = variableNamingStrategy; _variableNamingConvention = new CamelCaseVariableNamingConvention(); }
/// <summary>Visit a identifier.</summary> /// <param name="identifier">Identifier to be visited.</param> protected abstract void VisitIdentifier(Identifier identifier);
/// <summary>Creates a new blank query that can act as a sub query for this instance.</summary> /// <param name="subject">Primary subject of the resulting query.</param> /// <remarks>This method doesn't add the resulting query as a sub query of this instance.</remarks> /// <returns>Query that can act as a sub query for this instance.</returns> public Query CreateSubQuery(Identifier subject) { Query result = new Query(subject, _variableNamingStrategy); result.OwnerQuery = this; return result; }
/// <summary>Base constructor with component and alias passed.</summary> /// <param name="component">Component to be aliased.</param> /// <param name="name">Alias.</param> public Alias(IQueryComponent component, Identifier name) : base() { _component = component; _name = name; }
/// <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) { QuerySourceReferenceExpression querySource = FindQuerySource(selectClause.Selector); _visitor.VisitExpression(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); _query.Select.Add(genericConstrain); } _subject = _query.Subject; queryModel.MainFromClause.Accept(this, queryModel); _query.Select.Add(_mainFromComponent); VisitBodyClauses(queryModel.BodyClauses, queryModel); VisitResultOperators(queryModel.ResultOperators, queryModel); OverrideSelector(component, selectClause.Selector); }
internal EntityQueryModelVisitor(Query query, IEntityContext context) { _entityContext = context; _visitor = new EntityQueryVisitor(_query = (Query)(_result = query), _entityContext); _subject = null; }
private void OverrideEntitySelector(Identifier identifier) { UnboundConstrain genericConstrain = new UnboundConstrain(identifier, new Identifier(identifier.Name + "P"), new Identifier(identifier.Name + "O"), _mainFromComponent.SourceExpression.FromExpression); _mainFromComponent.Elements.Add(genericConstrain); _query.Select.Clear(); _query.Select.Add(genericConstrain); UnspecifiedEntityAccessor entityAccessor = new UnspecifiedEntityAccessor(identifier, _mainFromComponent); entityAccessor.Elements.Add(genericConstrain); _query.Select.Add(entityAccessor); int indexOf = -1; if ((indexOf = _query.Elements.IndexOf(_mainFromComponent)) != -1) { _query.Elements.RemoveAt(indexOf); _query.Elements.Insert(indexOf, entityAccessor); } else { _query.Elements.Add(entityAccessor); } if (_mainFromComponent.Elements[0] is UnboundConstrain) { _mainFromComponent.Elements.RemoveAt(0); } }
/// <summary>Visits an additional from clause.</summary> /// <param name="fromClause">From 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 VisitAdditionalFromClause(AdditionalFromClause fromClause, QueryModel queryModel, int index) { VisitQuerableFromClause(fromClause, queryModel, index); StrongEntityAccessor entityAccessor = (fromClause.FromExpression is System.Linq.Expressions.ConstantExpression ? null : _visitor.GetEntityAccessor(fromClause)); if (entityAccessor != null) { if ((entityAccessor.OwnerQuery == null) && (!_query.Elements.Contains(entityAccessor))) { _query.Elements.Add(entityAccessor); } } else { NonEntityQueryModelVisitor modelVisitor = new NonEntityQueryModelVisitor(_visitor); modelVisitor.VisitAdditionalFromClause(fromClause, queryModel, index); if (modelVisitor.From is Identifier) { _subject = (Identifier)modelVisitor.From; } else if (modelVisitor.From is IExpression) { _auxFromComponent = (IExpression)modelVisitor.From; } } base.VisitAdditionalFromClause(fromClause, queryModel, index); }