Ejemplo n.º 1
0
    public CloneContext (QuerySourceMapping querySourceMapping)
    {
      ArgumentUtility.CheckNotNull ("querySourceMapping", querySourceMapping);

      QuerySourceMapping = querySourceMapping;
    }
Ejemplo n.º 2
0
        public CloneContext(QuerySourceMapping querySourceMapping)
        {
            ArgumentUtility.CheckNotNull("querySourceMapping", querySourceMapping);

            QuerySourceMapping = querySourceMapping;
        }
    protected virtual void FlattenSubQuery (
        SubQueryExpression subQueryExpression, FromClauseBase fromClause, QueryModel queryModel, int destinationIndex)
    {
      ArgumentUtility.CheckNotNull ("subQueryExpression", subQueryExpression);
      ArgumentUtility.CheckNotNull ("fromClause", fromClause);
      ArgumentUtility.CheckNotNull ("queryModel", queryModel);

      CheckFlattenable (subQueryExpression.QueryModel);

      var innerMainFromClause = subQueryExpression.QueryModel.MainFromClause;
      CopyFromClauseData (innerMainFromClause, fromClause);

      var innerSelectorMapping = new QuerySourceMapping();
      innerSelectorMapping.AddMapping (fromClause, subQueryExpression.QueryModel.SelectClause.Selector);
      queryModel.TransformExpressions (ex => ReferenceReplacingExpressionTreeVisitor.ReplaceClauseReferences (ex, innerSelectorMapping, false));

      InsertBodyClauses (subQueryExpression.QueryModel.BodyClauses, queryModel, destinationIndex);

      var innerBodyClauseMapping = new QuerySourceMapping();
      innerBodyClauseMapping.AddMapping (innerMainFromClause, new QuerySourceReferenceExpression (fromClause));
      queryModel.TransformExpressions (ex => ReferenceReplacingExpressionTreeVisitor.ReplaceClauseReferences (ex, innerBodyClauseMapping, false));
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Clones this <see cref="QueryModel"/>, returning a new <see cref="QueryModel"/> equivalent to this instance, but with its clauses being
    /// clones of this instance's clauses. Any <see cref="QuerySourceReferenceExpression"/> in the cloned clauses that points back to another clause 
    /// in  this <see cref="QueryModel"/> (including its subqueries) is adjusted to point to the respective clones in the cloned 
    /// <see cref="QueryModel"/>. Any subquery nested in the <see cref="QueryModel"/> is also cloned.
    /// </summary>
    /// <param name="querySourceMapping">The <see cref="QuerySourceMapping"/> defining how to adjust instances of 
    /// <see cref="QuerySourceReferenceExpression"/> in the cloned <see cref="QueryModel"/>. If there is a <see cref="QuerySourceReferenceExpression"/>
    /// that points out of the <see cref="QueryModel"/> being cloned, specify its replacement via this parameter. At the end of the cloning process,
    /// this object maps all the clauses in this original <see cref="QueryModel"/> to the clones created in the process.
    /// </param>
    public QueryModel Clone (QuerySourceMapping querySourceMapping)
    {
      ArgumentUtility.CheckNotNull ("querySourceMapping", querySourceMapping);

      var cloneContext = new CloneContext (querySourceMapping);
      var queryModelBuilder = new QueryModelBuilder();

      queryModelBuilder.AddClause (MainFromClause.Clone (cloneContext));
      foreach (var bodyClause in BodyClauses)
        queryModelBuilder.AddClause (bodyClause.Clone (cloneContext));
      queryModelBuilder.AddClause (SelectClause.Clone (cloneContext));

      foreach (var resultOperator in ResultOperators)
      {
        var resultOperatorClone = resultOperator.Clone (cloneContext);
        queryModelBuilder.AddResultOperator (resultOperatorClone);
      }

      var clone = queryModelBuilder.Build ();
      clone.TransformExpressions (ex => CloningExpressionTreeVisitor.AdjustExpressionAfterCloning (ex, cloneContext.QuerySourceMapping));
      clone.ResultTypeOverride = ResultTypeOverride;
      return clone;
    }