Esempio n. 1
0
        private static string ComputeNavigationPath(EdmNavigationSourceKind kind, ODataUri odataUri, string navigationSource)
        {
            bool isContained        = kind == EdmNavigationSourceKind.ContainedEntitySet;
            bool isUnknownEntitySet = kind == EdmNavigationSourceKind.UnknownEntitySet;

            if (isUnknownEntitySet)
            {
                // If the navigation target is not specified, i.e., UnknownEntitySet,
                // the navigation path should be null so that type name will be used
                // to build the context Url.
                return(null);
            }

            string navigationPath = null;

            if (isContained && odataUri != null && odataUri.Path != null)
            {
                ODataPath odataPath = odataUri.Path.TrimEndingTypeSegment().TrimEndingKeySegment();
                if (!(odataPath.LastSegment is NavigationPropertySegment) && !(odataPath.LastSegment is OperationSegment))
                {
                    throw new ODataException(Strings.ODataContextUriBuilder_ODataPathInvalidForContainedElement(odataPath.ToContextUrlPathString()));
                }

                navigationPath = odataPath.ToContextUrlPathString();
            }

            return(navigationPath ?? navigationSource);
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        /// <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
            });
        }
Esempio n. 4
0
        /// <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)
            });
        }