Exemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of the <see cref="SelectExpandNode"/> class describing the set of structural properties,
        /// navigation properties, and actions to select and expand for the given <paramref name="writeContext"/>.
        /// </summary>
        /// <param name="entityType">The entity type of the entry that would be written.</param>
        /// <param name="writeContext">The serializer context to be used while creating the collection.</param>
        /// <remarks>The default constructor is for unit testing only.</remarks>
        public SelectExpandNode(IEdmEntityType entityType, ODataSerializerContext writeContext)
            : this(writeContext.SelectExpandClause, entityType, writeContext.Model)
        {
            var queryOptionParser = new ODataQueryOptionParser(
                writeContext.Model,
                entityType,
                writeContext.NavigationSource,
                _extraQueryParameters);

            var selectExpandClause = queryOptionParser.ParseSelectAndExpand();

            if (selectExpandClause != null)
            {
                foreach (SelectItem selectItem in selectExpandClause.SelectedItems)
                {
                    ExpandedNavigationSelectItem expandItem = selectItem as ExpandedNavigationSelectItem;
                    if (expandItem != null)
                    {
                        ValidatePathIsSupported(expandItem.PathToNavigationProperty);
                        NavigationPropertySegment navigationSegment  = (NavigationPropertySegment)expandItem.PathToNavigationProperty.LastSegment;
                        IEdmNavigationProperty    navigationProperty = navigationSegment.NavigationProperty;
                        if (!ExpandedNavigationProperties.ContainsKey(navigationProperty))
                        {
                            ExpandedNavigationProperties.Add(navigationProperty, expandItem.SelectAndExpand);
                        }
                    }
                }
            }
            SelectedNavigationProperties.ExceptWith(ExpandedNavigationProperties.Keys);
        }
Exemplo n.º 2
0
 private void BuildExpansions(SelectExpandClause selectExpandClause, HashSet <IEdmNavigationProperty> allNavigationProperties)
 {
     foreach (SelectItem selectItem in selectExpandClause.SelectedItems)
     {
         ExpandedNavigationSelectItem expandItem = selectItem as ExpandedNavigationSelectItem;
         if (expandItem != null)
         {
             ValidatePathIsSupported(expandItem.PathToNavigationProperty);
             NavigationPropertySegment navigationSegment  = (NavigationPropertySegment)expandItem.PathToNavigationProperty.LastSegment;
             IEdmNavigationProperty    navigationProperty = navigationSegment.NavigationProperty;
             if (allNavigationProperties.Contains(navigationProperty))
             {
                 ExpandedNavigationProperties.Add(navigationProperty, expandItem.SelectAndExpand);
             }
         }
     }
 }