private static ISet <IEdmStructuralProperty> GetPropertiesToIncludeInQuery( SelectExpandClause selectExpandClause, IEdmEntityType entityType, out ISet <IEdmStructuralProperty> autoSelectedProperties) { autoSelectedProperties = new HashSet <IEdmStructuralProperty>(); HashSet <IEdmStructuralProperty> propertiesToInclude = new HashSet <IEdmStructuralProperty>(); IEnumerable <SelectItem> selectedItems = selectExpandClause.SelectedItems; if (!IsSelectAll(selectExpandClause)) { // only select requested properties and keys. foreach (PathSelectItem pathSelectItem in selectedItems.OfType <PathSelectItem>()) { SelectExpandNode.ValidatePathIsSupported(pathSelectItem.SelectedPath); PropertySegment structuralPropertySegment = pathSelectItem.SelectedPath.LastSegment as PropertySegment; if (structuralPropertySegment != null) { propertiesToInclude.Add(structuralPropertySegment.Property); } } // add keys foreach (IEdmStructuralProperty keyProperty in entityType.Key()) { if (!propertiesToInclude.Contains(keyProperty)) { autoSelectedProperties.Add(keyProperty); } } } return(propertiesToInclude); }
public void ValidatePathIsSupported_ThrowsForUnsupportedPath() { ODataPath path = new ODataPath(new ValueSegment(previousType: null)); ExceptionAssert.Throws <ODataException>( () => SelectExpandNode.ValidatePathIsSupported(path), "A path within the select or expand query option is not supported."); }
private static Dictionary <IEdmNavigationProperty, ExpandedNavigationSelectItem> GetPropertiesToExpandInQuery(SelectExpandClause selectExpandClause) { Dictionary <IEdmNavigationProperty, ExpandedNavigationSelectItem> properties = new Dictionary <IEdmNavigationProperty, ExpandedNavigationSelectItem>(); foreach (SelectItem selectItem in selectExpandClause.SelectedItems) { ExpandedNavigationSelectItem expandItem = selectItem as ExpandedNavigationSelectItem; if (expandItem != null) { SelectExpandNode.ValidatePathIsSupported(expandItem.PathToNavigationProperty); NavigationPropertySegment navigationSegment = expandItem.PathToNavigationProperty.LastSegment as NavigationPropertySegment; if (navigationSegment == null) { throw new ODataException(SRResources.UnsupportedSelectExpandPath); } properties[navigationSegment.NavigationProperty] = expandItem; } } return(properties); }