/// <summary> /// Creates the <see cref="ODataNestedResourceInfo"/> to be written while writing this entity. /// </summary> /// <param name="navigationProperty">The navigation property for which the navigation link is being created.</param> /// <param name="resourceContext">The context for the entity instance being written.</param> /// <returns>The navigation link to be written.</returns> public virtual async Task <ODataNestedResourceInfo> CreateNavigationLinkAsync(IEdmNavigationProperty navigationProperty, ResourceContext resourceContext) { if (navigationProperty == null) { throw Error.ArgumentNull("navigationProperty"); } if (resourceContext == null) { throw Error.ArgumentNull("resourceContext"); } ODataSerializerContext writeContext = resourceContext.SerializerContext; ODataNestedResourceInfo navigationLink = null; if (writeContext.NavigationSource != null) { IEdmTypeReference propertyType = navigationProperty.Type; IEdmModel model = writeContext.Model; NavigationSourceLinkBuilderAnnotation linkBuilder = model.GetNavigationSourceLinkBuilder(writeContext.NavigationSource); Uri navigationUrl = await linkBuilder.BuildNavigationLinkAsync(resourceContext, navigationProperty, writeContext.MetadataLevel); navigationLink = new ODataNestedResourceInfo { IsCollection = propertyType.IsCollection(), Name = navigationProperty.Name, }; if (navigationUrl != null) { navigationLink.Url = navigationUrl; } } return(navigationLink); }