Exemple #1
0
        public void ValidatePathIsSupported_ThrowsForUnsupportedPathForSelect()
        {
            ODataPath path = new ODataPath(new ValueSegment(previousType: null));

            ExceptionAssert.Throws <ODataException>(
                () => SelectExpandNode.ValidatePathIsSupportedForSelect(path),
                "A path within the select or expand query option is not supported.");
        }
Exemple #2
0
        private static ISet <IEdmStructuralProperty> GetPropertiesToIncludeInQuery(
            SelectExpandClause selectExpandClause, IEdmStructuredType structuredType, IEdmNavigationSource navigationSource, IEdmModel model, out ISet <IEdmStructuralProperty> autoSelectedProperties)
        {
            IEdmEntityType entityType = structuredType as IEdmEntityType;

            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.ValidatePathIsSupportedForSelect(pathSelectItem.SelectedPath);
                    PropertySegment structuralPropertySegment = pathSelectItem.SelectedPath.LastSegment as PropertySegment;
                    if (structuralPropertySegment != null)
                    {
                        propertiesToInclude.Add(structuralPropertySegment.Property);
                    }
                }

                foreach (ExpandedNavigationSelectItem expandedNavigationSelectItem in selectedItems.OfType <ExpandedNavigationSelectItem>())
                {
                    foreach (var segment in expandedNavigationSelectItem.PathToNavigationProperty)
                    {
                        PropertySegment propertySegment = segment as PropertySegment;
                        if (propertySegment != null &&
                            structuredType.Properties().Contains(propertySegment.Property))
                        {
                            propertiesToInclude.Add(propertySegment.Property);
                            break;
                        }
                    }
                }

                if (entityType != null)
                {
                    // add keys
                    foreach (IEdmStructuralProperty keyProperty in entityType.Key())
                    {
                        if (!propertiesToInclude.Contains(keyProperty))
                        {
                            autoSelectedProperties.Add(keyProperty);
                        }
                    }
                }

                // add concurrency properties, if not added
                if (navigationSource != null && model != null)
                {
                    IEnumerable <IEdmStructuralProperty> concurrencyProperties = model.GetConcurrencyProperties(navigationSource);
                    foreach (IEdmStructuralProperty concurrencyProperty in concurrencyProperties)
                    {
                        if (!propertiesToInclude.Contains(concurrencyProperty))
                        {
                            autoSelectedProperties.Add(concurrencyProperty);
                        }
                    }
                }
            }

            return(propertiesToInclude);
        }