private void RemoveRedundantContainingPathSegments() { // Find the last non-contained navigation property segment: // Collection valued: entity set // -or- // Single valued: singleton // Copy over other path segments such as: not a navigation path segment, contained navigation property, // single valued navigation property with navigation source targetting an entity set (we won't have key // information for that navigation property.) _segments.Reverse(); NavigationPropertySegment navigationPropertySegment = null; List <ODataPathSegment> newSegments = new List <ODataPathSegment>(); foreach (ODataPathSegment segment in _segments) { navigationPropertySegment = segment as NavigationPropertySegment; if (navigationPropertySegment != null) { EdmNavigationSourceKind navigationSourceKind = navigationPropertySegment.NavigationSource.NavigationSourceKind(); if ((navigationPropertySegment.NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many && navigationSourceKind == EdmNavigationSourceKind.EntitySet) || (navigationSourceKind == EdmNavigationSourceKind.Singleton)) { break; } } newSegments.Insert(0, segment); } // Start the path with the navigation source of the navigation property found above. if (navigationPropertySegment != null) { IEdmNavigationSource navigationSource = navigationPropertySegment.NavigationSource; Contract.Assert(navigationSource != null); if (navigationSource.NavigationSourceKind() == EdmNavigationSourceKind.Singleton) { SingletonSegment singletonSegment = new SingletonSegment((IEdmSingleton)navigationSource); newSegments.Insert(0, singletonSegment); } else { Contract.Assert(navigationSource.NavigationSourceKind() == EdmNavigationSourceKind.EntitySet); EntitySetSegment entitySetSegment = new EntitySetSegment((IEdmEntitySet)navigationSource); newSegments.Insert(0, entitySetSegment); } } _segments = newSegments; }
private static Microsoft.OData.UriParser.ODataPath GeneratePath(IEdmNavigationSource navigationSource) { Contract.Assert(navigationSource != null); switch (navigationSource.NavigationSourceKind()) { case EdmNavigationSourceKind.EntitySet: return(new Microsoft.OData.UriParser.ODataPath(new EntitySetSegment((IEdmEntitySet)navigationSource))); case EdmNavigationSourceKind.Singleton: return(new Microsoft.OData.UriParser.ODataPath(new SingletonSegment((IEdmSingleton)navigationSource))); case EdmNavigationSourceKind.ContainedEntitySet: IEdmContainedEntitySet containedEntitySet = (IEdmContainedEntitySet)navigationSource; Microsoft.OData.UriParser.ODataPath path = GeneratePath(containedEntitySet.ParentNavigationSource); IList <ODataPathSegment> segments = new List <ODataPathSegment>(); foreach (var item in path) { segments.Add(item); } segments.Add(new NavigationPropertySegment(containedEntitySet.NavigationProperty, containedEntitySet.ParentNavigationSource)); return(new Microsoft.OData.UriParser.ODataPath(segments)); case EdmNavigationSourceKind.None: case EdmNavigationSourceKind.UnknownEntitySet: default: return(null); } }
/// <summary> /// Create ODataContextUrlInfo from basic information /// </summary> /// <param name="navigationSource">Navigation source for current element.</param>\ /// <param name="expectedEntityTypeName">The expectedEntity for current element.</param> /// <param name="isSingle">Whether target is single item.</param> /// <param name="odataUri">The odata uri info for current query.</param> /// <returns>The generated ODataContextUrlInfo.</returns> internal static ODataContextUrlInfo Create(IEdmNavigationSource navigationSource, string expectedEntityTypeName, bool isSingle, ODataUri odataUri) { EdmNavigationSourceKind kind = navigationSource.NavigationSourceKind(); string navigationSourceEntityType = navigationSource.EntityType().FullName(); return(new ODataContextUrlInfo() { isContained = kind == EdmNavigationSourceKind.ContainedEntitySet, navigationSource = navigationSource.Name, TypeCast = navigationSourceEntityType == expectedEntityTypeName ? null : expectedEntityTypeName, TypeName = navigationSourceEntityType, IncludeFragmentItemSelector = isSingle && kind != EdmNavigationSourceKind.Singleton, odataUri = odataUri }); }
/// <summary> /// Create ODataContextUrlInfo from basic information /// </summary> /// <param name="navigationSource">Navigation source for current element.</param>\ /// <param name="expectedEntityTypeName">The expectedEntity for current element.</param> /// <param name="isSingle">Whether target is single item.</param> /// <param name="odataUri">The odata uri info for current query.</param> /// <param name="version">The OData Version of the response.</param> /// <returns>The generated ODataContextUrlInfo.</returns> internal static ODataContextUrlInfo Create(IEdmNavigationSource navigationSource, string expectedEntityTypeName, bool isSingle, ODataUri odataUri, ODataVersion version) { EdmNavigationSourceKind kind = navigationSource.NavigationSourceKind(); string navigationSourceEntityType = navigationSource.EntityType().FullName(); return(new ODataContextUrlInfo() { IsUnknownEntitySet = kind == EdmNavigationSourceKind.UnknownEntitySet, NavigationSource = navigationSource.Name, TypeCast = navigationSourceEntityType == expectedEntityTypeName ? null : expectedEntityTypeName, TypeName = navigationSourceEntityType, IncludeFragmentItemSelector = isSingle && kind != EdmNavigationSourceKind.Singleton, NavigationPath = ComputeNavigationPath(kind, odataUri, navigationSource.Name), ResourcePath = ComputeResourcePath(odataUri), QueryClause = ComputeQueryClause(odataUri, version), IsUndeclared = ComputeIfIsUndeclared(odataUri) }); }
/// <summary> /// Create ODataContextUrlInfo from basic information /// </summary> /// <param name="navigationSource">Navigation source for current element.</param>\ /// <param name="expectedEntityTypeName">The expectedEntity for current element.</param> /// <param name="isSingle">Whether target is single item.</param> /// <param name="odataUri">The odata uri info for current query.</param> /// <returns>The generated ODataContextUrlInfo.</returns> internal static ODataContextUrlInfo Create(IEdmNavigationSource navigationSource, string expectedEntityTypeName, bool isSingle, ODataUri odataUri) { EdmNavigationSourceKind kind = navigationSource.NavigationSourceKind(); string navigationSourceEntityType = navigationSource.EntityType().FullName(); return new ODataContextUrlInfo() { isContained = kind == EdmNavigationSourceKind.ContainedEntitySet, IsUnknownEntitySet = kind == EdmNavigationSourceKind.UnknownEntitySet, navigationSource = navigationSource.Name, TypeCast = navigationSourceEntityType == expectedEntityTypeName ? null : expectedEntityTypeName, TypeName = navigationSourceEntityType, IncludeFragmentItemSelector = isSingle && kind != EdmNavigationSourceKind.Singleton, odataUri = odataUri }; }