/// <summary>
        /// Create a GroupByTransformationNode.
        /// </summary>
        /// <param name="groupingProperties">A list of <see cref="GroupByPropertyNode"/>.</param>
        /// <param name="childTransformations">The child <see cref="TransformationNode"/>.</param>
        /// <param name="source">The <see cref="CollectionNode"/> representing the source.</param>
        public GroupByTransformationNode(
            IList <GroupByPropertyNode> groupingProperties,
            TransformationNode childTransformations,
            CollectionNode source)
        {
            ExceptionUtils.CheckArgumentNotNull(groupingProperties, "groupingProperties");

            this.groupingProperties   = groupingProperties;
            this.childTransformations = childTransformations;
            this.source = source;
        }
예제 #2
0
        private GroupByTransformationNode BindGroupByToken(GroupByToken token)
        {
            var properties = new List <GroupByPropertyNode>();

            foreach (var propertyToken in token.Properties)
            {
                var bindResult = this.bindMethod(propertyToken);
                var property   = bindResult as SingleValuePropertyAccessNode;

                if (property != null)
                {
                    RegisterProperty(properties, ReversePropertyPath(property));
                }
                else
                {
                    var openProperty = bindResult as SingleValueOpenPropertyAccessNode;
                    if (openProperty != null)
                    {
                        var type = GetTypeReferenceByPropertyName(openProperty.Name);
                        properties.Add(new GroupByPropertyNode(openProperty.Name, openProperty, type));
                    }
                    else
                    {
                        throw new ODataException(
                                  ODataErrorStrings.ApplyBinder_GroupByPropertyNotPropertyAccessValue(propertyToken.Identifier));
                    }
                }
            }

            TransformationNode aggregate = null;

            if (token.Child != null)
            {
                if (token.Child.Kind == QueryTokenKind.Aggregate)
                {
                    aggregate = BindAggregateToken((AggregateToken)token.Child);
                    aggregateExpressionsCache     = ((AggregateTransformationNode)aggregate).Expressions;
                    state.AggregatedPropertyNames =
                        aggregateExpressionsCache.Select(statement => statement.Alias).ToList();
                }
                else
                {
                    throw new ODataException(ODataErrorStrings.ApplyBinder_UnsupportedGroupByChild(token.Child.Kind));
                }
            }

            // TODO: Determine source
            return(new GroupByTransformationNode(properties, aggregate, null));
        }