Example #1
0
        /// <summary>uri to edit the entity</summary>
        /// <param name="baseUriResolver">retrieves the baseUri to use for a given entity set.</param>
        /// <param name="queryLink">whether to return the query link or edit link</param>
        /// <returns>absolute uri which can be used to edit the entity</returns>
        internal Uri GetResourceUri(UriResolver baseUriResolver, bool queryLink)
        {
            // If the entity was inserted using the AddRelatedObject API
            if (this.ParentForInsert != null)
            {
                // This is the batch scenario, where the entity might not have been saved yet, and there is another operation
                // (for e.g. PUT $1/links/BestFriend or something). Hence we need to generate a Uri with the changeorder number.
                if (this.ParentForInsert.Identity == null)
                {
                    Uri relativeReferenceUri = UriUtil.CreateUri("$" + this.ParentForInsert.ChangeOrder.ToString(CultureInfo.InvariantCulture), UriKind.Relative);
                    Uri absoluteReferenceUri = baseUriResolver.GetOrCreateAbsoluteUri(relativeReferenceUri);
                    Uri requestUri           = UriUtil.CreateUri(this.ParentPropertyForInsert, UriKind.Relative);
                    return(UriUtil.CreateUri(absoluteReferenceUri, requestUri));
                }
                else
                {
                    Debug.Assert(this.ParentForInsert.ParentForInsert == null, "This code assumes that parentChild relationships will only ever be one level deep");
                    Debug.Assert(this.ParentPropertyForInsert != null, "parentProperty != null");
                    LinkInfo linkInfo;
                    if (this.ParentForInsert.TryGetLinkInfo(this.ParentPropertyForInsert, out linkInfo))
                    {
                        if (linkInfo.NavigationLink != null)
                        {
                            return(linkInfo.NavigationLink);
                        }
                    }

                    return(UriUtil.CreateUri(this.ParentForInsert.GetLink(queryLink), this.GetLink(queryLink)));
                }
            }
            else
            {
                return(this.GetLink(queryLink));
            }
        }