Esempio n. 1
0
        private ODataPathKind CalcPathType()
        {
            if (Segments.Count == 1 && Segments.First().Kind == ODataSegmentKind.Metadata)
            {
                return(ODataPathKind.Metadata);
            }

            if (Segments.Last().Kind == ODataSegmentKind.DollarCount)
            {
                return(ODataPathKind.DollarCount);
            }

            if (Segments.Any(c => c.Kind == ODataSegmentKind.StreamProperty || c.Kind == ODataSegmentKind.StreamContent))
            {
                return(ODataPathKind.MediaEntity);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.Ref))
            {
                return(ODataPathKind.Ref);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.OperationImport))
            {
                return(ODataPathKind.OperationImport);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.Operation))
            {
                return(ODataPathKind.Operation);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.NavigationProperty))
            {
                return(ODataPathKind.NavigationProperty);
            }

            if (Segments.Count == 1)
            {
                ODataNavigationSourceSegment segment = Segments[0] as ODataNavigationSourceSegment;
                if (segment != null)
                {
                    if (segment.NavigationSource is IEdmSingleton)
                    {
                        return(ODataPathKind.Singleton);
                    }
                    else
                    {
                        return(ODataPathKind.EntitySet);
                    }
                }
            }
            else if (Segments.Count == 2 && Segments.Last().Kind == ODataSegmentKind.Key)
            {
                return(ODataPathKind.Entity);
            }

            return(ODataPathKind.Unknown);
        }
        private void AppendPath(ODataPath path)
        {
            Debug.Assert(path != null);

            ODataPathKind kind = path.Kind;

            switch (kind)
            {
            case ODataPathKind.Entity:
            case ODataPathKind.EntitySet:
            case ODataPathKind.Singleton:
            case ODataPathKind.MediaEntity:
                ODataNavigationSourceSegment navigationSourceSegment = (ODataNavigationSourceSegment)path.FirstSegment;
                if (!_allNavigationSourcePaths.TryGetValue(navigationSourceSegment.EntityType, out IList <ODataPath> nsList))
                {
                    nsList = new List <ODataPath>();
                    _allNavigationSourcePaths[navigationSourceSegment.EntityType] = nsList;
                }

                nsList.Add(path);
                break;

            case ODataPathKind.NavigationProperty:
            case ODataPathKind.Ref:
                ODataNavigationPropertySegment navigationPropertySegment = path.Last(p => p is ODataNavigationPropertySegment)
                                                                           as ODataNavigationPropertySegment;

                if (!_allNavigationPropertyPaths.TryGetValue(navigationPropertySegment.EntityType, out IList <ODataPath> npList))
                {
                    npList = new List <ODataPath>();
                    _allNavigationPropertyPaths[navigationPropertySegment.EntityType] = npList;
                }

                npList.Add(path);
                break;

            case ODataPathKind.Operation:
            case ODataPathKind.OperationImport:
                _allOperationPaths.Add(path);
                break;

            default:
                return;
            }
        }