public void Process(FetchRequestBase resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree, string sourceAlias, bool userInnerJoin = false)
        {
            var join = tree.TreeBuilder.Dot(
                tree.TreeBuilder.Ident(sourceAlias),
                tree.TreeBuilder.Ident(resultOperator.RelationMember.Name));

            string alias = queryModelVisitor.Model.GetNewName("_");

            if (userInnerJoin)
            {
                tree.AddFromClause(tree.TreeBuilder.FetchJoin(join, tree.TreeBuilder.Alias(alias)));
            }
            else
            {
                tree.AddFromClause(tree.TreeBuilder.LeftFetchJoin(join, tree.TreeBuilder.Alias(alias)));
            }

            tree.AddDistinctRootOperator();

            foreach (var innerFetch in resultOperator.InnerFetchRequests)
            {
                if (innerFetch is InnerFetchOneRequest || innerFetch is InnerFetchManyRequest)
                {
                    Process(innerFetch, queryModelVisitor, tree, alias, true);
                }
                else
                {
                    Process(innerFetch, queryModelVisitor, tree, alias);
                }
            }
        }
    /// <summary>
    /// Initializes a new instance of the <see cref="FetchQueryModelBuilder"/> class.
    /// </summary>
    /// <param name="fetchRequest">The fetch request.</param>
    /// <param name="queryModel">The query model for which the <paramref name="fetchRequest"/> was originally defined.</param>
    /// <param name="resultOperatorPosition">The result operator position where the <paramref name="fetchRequest"/> was originally located.
    /// The <see cref="FetchQueryModelBuilder"/> will include all result operators prior to this position into the fetch <see cref="SourceItemQueryModel"/>,
    /// but it will not include any result operators occurring after (or at) that position.</param>
    public FetchQueryModelBuilder (FetchRequestBase fetchRequest, QueryModel queryModel, int resultOperatorPosition)
    {
      ArgumentUtility.CheckNotNull ("fetchRequest", fetchRequest);
      ArgumentUtility.CheckNotNull ("queryModel", queryModel);

      FetchRequest = fetchRequest;
      SourceItemQueryModel = queryModel;
      ResultOperatorPosition = resultOperatorPosition;
    }
    /// <summary>
    /// Gets or adds an eager-fetch request to this <see cref="FetchRequestCollection"/>.
    /// </summary>
    /// <param name="fetchRequest">The <see cref="FetchRequestBase"/> to be added.</param>
    /// <returns>
    /// <paramref name="fetchRequest"/> or, if another <see cref="FetchRequestBase"/> for the same relation member already existed,
    /// the existing <see cref="FetchRequestBase"/>.
    /// </returns>
    public FetchRequestBase GetOrAddFetchRequest (FetchRequestBase fetchRequest)
    {
      ArgumentUtility.CheckNotNull ("fetchRequest", fetchRequest);

      FetchRequestBase existingFetchRequest;
      if (_fetchRequests.TryGetValue (fetchRequest.RelationMember, out existingFetchRequest))
        return existingFetchRequest;
      else
      {
        _fetchRequests.Add (fetchRequest.RelationMember, fetchRequest);
        return fetchRequest;
      }
    }
Example #4
0
        public void Process(FetchRequestBase resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
        {
            var querySource = QuerySourceLocator.FindQuerySource(queryModelVisitor.Model, resultOperator.RelationMember.DeclaringType);

            Process(resultOperator, queryModelVisitor, tree, querySource.ItemName);
        }