internal static Uri GenerateActionLink(this ResourceSetContext resourceSetContext, IEdmTypeReference bindingParameterType,
                                               IEdmOperation action)
        {
            Contract.Assert(resourceSetContext != null);

            if (resourceSetContext.EntitySetBase is IEdmContainedEntitySet)
            {
                return(null);
            }

            IList <ODataPathSegment> actionPathSegments = new List <ODataPathSegment>();

            resourceSetContext.GenerateBaseODataPathSegmentsForFeed(actionPathSegments);

            // generate link with cast if the navigation source doesn't match the type the action is bound to.
            if (resourceSetContext.EntitySetBase.Type.FullTypeName() != bindingParameterType.FullName())
            {
                actionPathSegments.Add(new TypeSegment(bindingParameterType.Definition, resourceSetContext.EntitySetBase));
            }

            OperationSegment operationSegment = new OperationSegment(action, entitySet: null);

            actionPathSegments.Add(operationSegment);

            string actionLink = resourceSetContext.Request.CreateODataLink(actionPathSegments);

            return(actionLink == null ? null : new Uri(actionLink));
        }
        internal static Uri GenerateFunctionLink(this ResourceSetContext resourceSetContext, IEdmTypeReference bindingParameterType,
                                                 IEdmOperation functionImport, IEnumerable <string> parameterNames)
        {
            Contract.Assert(resourceSetContext != null);

            if (resourceSetContext.EntitySetBase is IEdmContainedEntitySet)
            {
                return(null);
            }

            IList <ODataPathSegment> functionPathSegments = new List <ODataPathSegment>();

            resourceSetContext.GenerateBaseODataPathSegmentsForFeed(functionPathSegments);

            // generate link with cast if the navigation source type doesn't match the entity type the function is bound to.
            if (resourceSetContext.EntitySetBase.Type.FullTypeName() != bindingParameterType.Definition.FullTypeName())
            {
                functionPathSegments.Add(new TypeSegment(bindingParameterType.Definition, null));
            }

            IList <OperationSegmentParameter> parameters = new List <OperationSegmentParameter>();

            // skip the binding parameter
            foreach (string param in parameterNames.Skip(1))
            {
                string value = "@" + param;
                parameters.Add(new OperationSegmentParameter(param, new ConstantNode(value, value)));
            }

            OperationSegment segment = new OperationSegment(new[] { functionImport }, parameters, null);

            functionPathSegments.Add(segment);

            string functionLink = resourceSetContext.Request.CreateODataLink(functionPathSegments);

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