If you look at the following sample oData feed you'll see included navigation properties for 'child' items to tell you which URL to follow:
http://services.odata.org/OData/OData.svc/Suppliers?$format=json
For example supplier 0 has a navigation property to products. This links to a list of products for that supplier.
http://services.odata.org/OData/OData.svc/Suppliers(0)/Products?$format=json
I'm trying to do the same with ODataConventionModelBuilder
and EntitySetController<Product>
so that when I request oData/Product(0)
it will show me the 'features' for the product:
I create my model like this (based on GetImplicitEdmModel sample)
// odata
ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<RRStoreDB.Models.Product>("Product");
modelBuilder.EntitySet<RRStoreDB.Models.ProductFeature>("ProductFeature");
Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel();
config.Routes.MapODataRoute("ODataRoute", "odata", model);
I create a controller for WebAPI :
public class ProductController : EntitySetController<Product, int>
{
RRStoreDBContext _db = new RRStoreDBContext();
[Queryable]
public override IQueryable<DProduct> Get()
{
return _db.Products.AsQueryable();
}
public ICollection<ProductFeature> GetProductFeatures(int key)
{
Product product = _db.Products.FirstOrDefault(p => p.ProductId == key);
if (product == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return product.ProductFeatures;
}
}
When I actually call the URL for my child property it works and gives me the correct list of features :
/oData/Products(18)/ProductFeatures
However I would have expected a navigation property in /oData/Products(18)
pointing to this.
What do I need to do to get this to appear. This article says it's automatic but I'm not seeing them:
The ODataConventionModelBuilder, which is generally recommended over the ODataModelBuilder, will automatically infer inheritance hierarchies in the absence of explicit configuration. Then once the hierarchy is inferred, it will also infer properties and navigation properties too. This allows you to write less code, focusing on where you deviate from our conventions.
Not implemented, This service doesn't support OData requests in the form '~/entityset/key/unresolved'.
You could solve the problem? – ridermansb