예제 #1
0
 private void BuildExpansions(SelectExpandClause selectExpandClause, HashSet <IEdmNavigationProperty> allNavigationProperties)
 {
     foreach (SelectItem selectItem in selectExpandClause.SelectedItems)
     {
         ExpandedReferenceSelectItem expandReferenceItem = selectItem as ExpandedReferenceSelectItem;
         if (expandReferenceItem != null)
         {
             ValidatePathIsSupported(expandReferenceItem.PathToNavigationProperty);
             NavigationPropertySegment navigationSegment  = (NavigationPropertySegment)expandReferenceItem.PathToNavigationProperty.LastSegment;
             IEdmNavigationProperty    navigationProperty = navigationSegment.NavigationProperty;
             if (allNavigationProperties.Contains(navigationProperty))
             {
                 ExpandedNavigationSelectItem expandItem = selectItem as ExpandedNavigationSelectItem;
                 if (expandItem != null)
                 {
                     ExpandedProperties.Add(navigationProperty, expandItem);
                 }
                 else
                 {
                     ReferencedNavigationProperties.Add(navigationProperty);
                 }
             }
         }
     }
 }
예제 #2
0
        private void BuildExpansions(IEnumerable <SelectItem> selectedItems, HashSet <IEdmNavigationProperty> allNavigationProperties)
        {
            foreach (SelectItem selectItem in selectedItems)
            {
                ExpandedReferenceSelectItem expandReferenceItem = selectItem as ExpandedReferenceSelectItem;
                if (expandReferenceItem != null)
                {
                    ValidatePathIsSupportedForExpand(expandReferenceItem.PathToNavigationProperty);
                    NavigationPropertySegment navigationSegment  = (NavigationPropertySegment)expandReferenceItem.PathToNavigationProperty.LastSegment;
                    IEdmNavigationProperty    navigationProperty = navigationSegment.NavigationProperty;

                    int propertyCountInPath =
                        expandReferenceItem.PathToNavigationProperty.OfType <PropertySegment>().Count();

                    bool numberOfPropertiesInPathMatch =
                        (propertyCountInPath > 0 && PropertiesInPath != null &&
                         PropertiesInPath.Count == propertyCountInPath) || propertyCountInPath < 1;

                    if (numberOfPropertiesInPathMatch && allNavigationProperties.Contains(navigationProperty))
                    {
                        ExpandedNavigationSelectItem expandItem = selectItem as ExpandedNavigationSelectItem;
                        if (expandItem != null)
                        {
                            if (!ExpandedProperties.ContainsKey(navigationProperty))
                            {
                                ExpandedProperties.Add(navigationProperty, expandItem);
                            }
                            else
                            {
                                ExpandedProperties[navigationProperty] = expandItem;
                            }
                        }
                        else
                        {
                            ReferencedNavigationProperties.Add(navigationProperty);
                        }
                    }
                    else
                    {
                        //This is the case where the navigation property is not on the current type. We need to propagate the expand item to deeper SelectExpandNode.
                        IEdmStructuralProperty complexProperty = FindNextPropertySegment(expandReferenceItem.PathToNavigationProperty);

                        if (complexProperty != null)
                        {
                            SelectExpandClause newClause;
                            if (ExpandedPropertiesOnSubChildren.ContainsKey(complexProperty))
                            {
                                SelectExpandClause oldClause = ExpandedPropertiesOnSubChildren[complexProperty].SelectAndExpand;
                                newClause = new SelectExpandClause(
                                    oldClause.SelectedItems.Concat(new SelectItem[] { expandReferenceItem }), false);
                                ExpandedNavigationSelectItem newItem = new ExpandedNavigationSelectItem(expandReferenceItem.PathToNavigationProperty, navigationSegment.NavigationSource, newClause);
                                ExpandedPropertiesOnSubChildren[complexProperty] = newItem;
                            }
                            else
                            {
                                newClause = new SelectExpandClause(new SelectItem[] { expandReferenceItem }, false);
                                ExpandedNavigationSelectItem newItem = new ExpandedNavigationSelectItem(expandReferenceItem.PathToNavigationProperty, navigationSegment.NavigationSource, newClause);
                                ExpandedPropertiesOnSubChildren.Add(complexProperty, newItem);
                            }
                        }
                    }
                }
            }
        }