How to configure links with HasNavigationPropertiesLink after the last update of WebAPI beta (26-June-2013)

advertisements

I have a basic POCO (No database) structure implementing an OData Service with the latest WebAPI update. Unfortunately, the latest update broke the HasNavigationPropertiesLink code that I had to generate links which can be used for $expand operations. Here is my old code:

var jobs = modelBuilder.EntitySet<Job>("Jobs");
jobs.EntityType.NavigationProperties,
            (entityContext, navigationProperty) => new
             Uri(entityContext.UrlHelper.Link(ODataRouteNames.PropertyNavigation,
                   new
                      {
                           Controller = "Jobs",
                           parentId = entityContext.EntityInstance.ID,
                           NavigationProperty = navigationProperty.Name
                       })));

And here is my new code (that doesn't work):

var jobs = modelBuilder.EntitySet<Job>("Jobs");
jobs.EntityType.NavigationProperties,
            (entityContext, navigationProperty) => new
             Uri(entityContext.Url.Link(<??WHAT GOES HERE??>,
                   new
                      {
                           Controller = "Jobs",
                           parentId = entityContext.EdmObject,
                           NavigationProperty = navigationProperty.Name
                       })),
                       true);

Any help is much appreciated - this doesn't seem to have been documented in the updates.


looks like the version of the OData bits you are using is very old. In our current version, you can use the ODataConventionsModelBuilder to create a model that defines navigation properties and links following conventions, so unless you need to generate custom links, it's a better way to go. However, if you want to generate a custom navigation link, the link generation code looks something similar to this:

        var jobs = builder.EntitySet<Job>("Jobs");
        jobs.HasNavigationPropertiesLink(customers.EntityType.NavigationProperties,
            (context, navigationProperty) =>
            {
                var result = "http://mydomain.com/prefix/odataPath";
                //In order to generate this link you can use context.Url.ODataLink(new EntityPathSegment("Jobs"), ...);
                return new Uri(result);
            }, followsConventions: true);