Exemplo n.º 1
0
        /// <summary>
        /// Generates a navigation link following the OData URL conventions for the entity represented by <paramref name="entityContext"/> and the given
        /// navigation property.
        /// </summary>
        /// <param name="entityContext">The <see cref="EntityInstanceContext"/> representing the entity for which the navigation link needs to be generated.</param>
        /// <param name="navigationProperty">The EDM navigation property.</param>
        /// <param name="includeCast">Represents whether the generated link should have a cast segment representing a type cast.</param>
        /// <returns>The navigation link following the OData URL conventions.</returns>
        public static Uri GenerateNavigationPropertyLink(this EntityInstanceContext entityContext, IEdmNavigationProperty navigationProperty, bool includeCast)
        {
            if (entityContext == null)
            {
                throw Error.ArgumentNull("entityContext");
            }
            if (entityContext.Url == null)
            {
                throw Error.Argument("entityContext", SRResources.UrlHelperNull, typeof(EntityInstanceContext).Name);
            }

            IList <ODataPathSegment> navigationPathSegments = entityContext.GenerateBaseODataPathSegments();

            if (includeCast)
            {
                navigationPathSegments.Add(new CastPathSegment(entityContext.EntityType));
            }

            navigationPathSegments.Add(new NavigationPathSegment(navigationProperty));

            string link = entityContext.Url.CreateODataLink(navigationPathSegments);

            if (link == null)
            {
                return(null);
            }

            return(new Uri(link));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates a self link following the OData URL conventions for the entity represented by <paramref name="entityContext"/>.
        /// </summary>
        /// <param name="entityContext">The <see cref="EntityInstanceContext"/> representing the entity for which the self link needs to be generated.</param>
        /// <param name="includeCast">Represents whether the generated link should have a cast segment representing a type cast.</param>
        /// <returns>The self link following the OData URL conventions.</returns>
        public static Uri GenerateSelfLink(this EntityInstanceContext entityContext, bool includeCast)
        {
            if (entityContext == null)
            {
                throw Error.ArgumentNull("entityContext");
            }
            if (entityContext.Url == null)
            {
                throw Error.Argument("entityContext", SRResources.UrlHelperNull, typeof(EntityInstanceContext).Name);
            }

            IList <ODataPathSegment> idLinkPathSegments = entityContext.GenerateBaseODataPathSegments();

            bool isSameType = entityContext.EntityType == entityContext.NavigationSource.EntityType();

            if (includeCast && !isSameType)
            {
                idLinkPathSegments.Add(new CastPathSegment(entityContext.EntityType));
            }

            string idLink = entityContext.Url.CreateODataLink(idLinkPathSegments);

            if (idLink == null)
            {
                return(null);
            }

            return(new Uri(idLink));
        }
Exemplo n.º 3
0
        internal static Uri GenerateActionLink(this EntityInstanceContext entityContext, string bindingParameterType, string actionName)
        {
            Contract.Assert(entityContext != null);
            if (entityContext.NavigationSource is IEdmContainedEntitySet)
            {
                return(null);
            }

            IList <ODataPathSegment> actionPathSegments = entityContext.GenerateBaseODataPathSegments();

            // generate link with cast if the navigation source doesn't match the entity type the action is bound to.
            if (entityContext.NavigationSource.EntityType().FullName() != bindingParameterType)
            {
                actionPathSegments.Add(new CastPathSegment(bindingParameterType));
            }

            actionPathSegments.Add(new BoundActionPathSegment(actionName));

            string actionLink = entityContext.Url.CreateODataLink(actionPathSegments);

            return(actionLink == null ? null : new Uri(actionLink));
        }
Exemplo n.º 4
0
        internal static Uri GenerateFunctionLink(this EntityInstanceContext entityContext, string bindingParameterType, string functionName, IEnumerable <string> parameterNames)
        {
            IList <ODataPathSegment> functionPathSegments = entityContext.GenerateBaseODataPathSegments();

            // generate link with cast if the navigation source type doesn't match the entity type the function is bound to.
            if (entityContext.NavigationSource.EntityType().FullName() != bindingParameterType)
            {
                functionPathSegments.Add(new CastPathSegment(bindingParameterType));
            }

            Dictionary <string, string> parametersDictionary = new Dictionary <string, string>();

            foreach (string param in parameterNames)
            {
                parametersDictionary.Add(param, "@" + param);
            }

            functionPathSegments.Add(new BoundFunctionPathSegment(functionName, parametersDictionary));

            string functionLink = entityContext.Url.CreateODataLink(functionPathSegments);

            return(functionLink == null ? null : new Uri(functionLink));
        }