public QueryModel Apply (QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
    {
      if (queryModel != null)
        throw new ArgumentException ("QueryModel has to be null because MainSourceExpressionNode marks the start of a query.", "queryModel");

      var mainFromClause = CreateMainFromClause (clauseGenerationContext);
      var defaultSelectClause = new SelectClause (new QuerySourceReferenceExpression (mainFromClause));
      return new QueryModel (mainFromClause, defaultSelectClause) { ResultTypeOverride = QuerySourceType };
    }
예제 #2
0
    /// <summary>
    /// Modifies the given query model for fetching, adding an <see cref="AdditionalFromClause"/> and changing the <see cref="SelectClause.Selector"/> to 
    /// retrieve the result of the <see cref="AdditionalFromClause"/>.
    /// For example, a fetch request such as <c>FetchMany (x => x.Orders)</c> will be transformed into a <see cref="AdditionalFromClause"/> selecting
    /// <c>y.Orders</c> (where <c>y</c> is what the query model originally selected) and a <see cref="SelectClause"/> selecting the result of the
    /// <see cref="AdditionalFromClause"/>.
    /// This method is called by <see cref="FetchRequestBase.CreateFetchQueryModel"/> in the process of creating the new fetch query model.
    /// </summary>
    protected override void ModifyFetchQueryModel (QueryModel fetchQueryModel)
    {
      ArgumentUtility.CheckNotNull ("fetchQueryModel", fetchQueryModel);

      var fromExpression = GetFetchedMemberExpression (new QuerySourceReferenceExpression (fetchQueryModel.MainFromClause));
      var memberFromClause = new AdditionalFromClause (fetchQueryModel.GetNewName ("#fetch"), _relatedObjectType, fromExpression);
      fetchQueryModel.BodyClauses.Add (memberFromClause);

      var newSelector = new QuerySourceReferenceExpression (memberFromClause);
      var newSelectClause = new SelectClause (newSelector);
      fetchQueryModel.SelectClause = newSelectClause;
    }
예제 #3
0
    /// <summary>
    /// Initializes a new instance of <see cref="QueryModel"/>
    /// </summary>
    /// <param name="mainFromClause">The <see cref="Clauses.MainFromClause"/> of the query. This is the starting point of the query, generating items 
    /// that are filtered and projected by the query.</param>
    /// <param name="selectClause">The <see cref="SelectClause"/> of the query. This is the end point of
    /// the query, it defines what is actually returned for each of the items coming from the <see cref="MainFromClause"/> and passing the 
    /// <see cref="BodyClauses"/>. After it, only the <see cref="ResultOperators"/> modify the result of the query.</param>
    public QueryModel (MainFromClause mainFromClause, SelectClause selectClause)
    {
      ArgumentUtility.CheckNotNull ("mainFromClause", mainFromClause);
      ArgumentUtility.CheckNotNull ("selectClause", selectClause);

      _uniqueIdentifierGenerator = new UniqueIdentifierGenerator();

      MainFromClause = mainFromClause;
      SelectClause = selectClause;

      BodyClauses = new ObservableCollection<IBodyClause>();
      BodyClauses.CollectionChanged += BodyClauses_CollectionChanged;

      ResultOperators = new ObservableCollection<ResultOperatorBase>();
      ResultOperators.CollectionChanged += ResultOperators_CollectionChanged;
    }
    public virtual void VisitSelectClause (SelectClause selectClause, QueryModel queryModel)
    {
      ArgumentUtility.CheckNotNull ("selectClause", selectClause);
      ArgumentUtility.CheckNotNull ("queryModel", queryModel);

      // nothing to do here
    }
예제 #5
0
 public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
 {
     QueryText.Append(" return ");
     GetAqlExpression(selectClause.Selector, queryModel);
 }
예제 #6
0
    /// <summary>
    /// Clones this clause.
    /// </summary>
    /// <param name="cloneContext">The clones of all query source clauses are registered with this <see cref="CloneContext"/>.</param>
    /// <returns>A clone of this clause.</returns>
    public SelectClause Clone (CloneContext cloneContext)
    {
      ArgumentUtility.CheckNotNull ("cloneContext", cloneContext);

      var result = new SelectClause (Selector);
      return result;
    }
예제 #7
0
    /// <summary>
    /// Creates a new <see cref="QueryModel"/> that has this <see cref="QueryModel"/> as a sub-query in its <see cref="MainFromClause"/>.
    /// </summary>
    /// <param name="itemName">The name of the new <see cref="QueryModel"/>'s <see cref="FromClauseBase.ItemName"/>.</param>
    /// <returns>A new <see cref="QueryModel"/> whose <see cref="MainFromClause"/>'s <see cref="FromClauseBase.FromExpression"/> is a 
    /// <see cref="SubQueryExpression"/> that holds this <see cref="QueryModel"/> instance.</returns>
    public QueryModel ConvertToSubQuery (string itemName)
    {
      ArgumentUtility.CheckNotNullOrEmpty ("itemName", itemName);

      var outputDataInfo = GetOutputDataInfo() as StreamedSequenceInfo;
      if (outputDataInfo == null)
      {
        var message = string.Format (
            "The query must return a sequence of items, but it selects a single object of type '{0}'.",
            GetOutputDataInfo ().DataType);
        throw new InvalidOperationException (message);
      }

      // from x in (sourceItemQuery)
      // select x

      var mainFromClause = new MainFromClause (
          itemName, 
          outputDataInfo.ResultItemType, 
          new SubQueryExpression (this));
      var selectClause = new SelectClause (new QuerySourceReferenceExpression (mainFromClause));
      return new QueryModel (mainFromClause, selectClause);
    }