/// <summary>
        /// Builds the artifact for the root resource of the composite definition.
        /// </summary>
        /// <param name="parentResult">The parent build result, for compositional behavior (if applicable).</param>
        /// <param name="builderContext">The builder context.</param>
        /// <param name="processorContext">The composite definition processor context.</param>
        /// <returns>The build result.</returns>
        public CompositeQuery BuildForChildResource(
            CompositeQuery parentResult,
            HqlBuilderContext builderContext,
            CompositeDefinitionProcessorContext processorContext)
        {
            ApplyFilters(processorContext, builderContext);

            return(_next.BuildForChildResource(parentResult, builderContext, processorContext));
        }
        private TBuildResult ProcessDefinition(
            TBuildResult parentResult,
            TBuilderContext builderContext,
            CompositeDefinitionProcessorContext processorContext)
        {
            // Apply authorization for aggregate roots here
            if (processorContext.CurrentResourceClass.Entity.IsAggregateRoot)
            {
                // Provide opportunity to perform processing related to navigating into another resource (i.e. authorization)
                if (!_compositeBuilder.TryIncludeResource(processorContext, builderContext))
                {
                    return(default(TBuildResult));
                }
            }

            bool isMainQuery = processorContext.IsBaseResource();

            if (isMainQuery)
            {
                _compositeBuilder.ApplyRootResource(processorContext, builderContext);
            }
            else
            {
                _compositeBuilder.ApplyChildResource(builderContext, processorContext);
            }

            var nonIncomingIdentifyingProperties = processorContext.NonIncomingIdentifyingProperties();

            ApplyLocalIdentifyingProperties(builderContext, processorContext, nonIncomingIdentifyingProperties);

            // Capture current applicable builder state so it can be modified further at this level without changes affecting children
            _compositeBuilder.SnapshotParentingContext(builderContext);

            // Select projected properties
            var propertyProjections = GetPropertyProjections(processorContext, processorContext.PropertyElements());

            // Project the properties into the artifact under construction
            _compositeBuilder.ProjectProperties(propertyProjections, builderContext, processorContext);

            // Process flattened References
            ProcessFlattenedMemberProperties(processorContext, builderContext);

            TBuildResult thisBuildResult;

            if (isMainQuery)
            {
                // Short circuit the rest of the processing if the root result is null
                if (!_compositeBuilder.TryBuildForRootResource(builderContext, processorContext, out thisBuildResult))
                {
                    return(default(TBuildResult));
                }
            }
            else
            {
                thisBuildResult = _compositeBuilder.BuildForChildResource(
                    parentResult,
                    builderContext,
                    processorContext);
            }

            var childBuilderContext = _compositeBuilder.CreateParentingContext(builderContext);

            ProcessChildren(thisBuildResult, processorContext, childBuilderContext);

            if (_performValidation && _validationErrors.Any())
            {
                throw new Exception(string.Join(Environment.NewLine, _validationErrors.ToArray()));
            }

            return(thisBuildResult);
        }