If you look at the following oData file example, which you will see, enable the navigation properties for the "children" elements to tell you which URL should be:
http://services.odata.org/OData/OData.svc/Suppliers?$format=json
For example, provider 0 has a navigation property for products. This refers to the product list for this vendor.
http://services.odata.org/OData/OData.svc/Suppliers (0) / Products? $ format = json
I am trying to do the same with ODataConventionModelBuilder and EntitySetController<Product> so that when I request oData/Product(0) it will show me the โfunctionsโ for the product:
I create my model as follows (based on GetImplicitEdmModel example )
// 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 am creating 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 functions:
/oData/Products(18)/ProductFeatures
However, I would suggest that the navigation property in /oData/Products(18) points to this.
What I need to do to make it appear. This article says that it is automatic, but I do not see them:
ODataConventionModelBuilder, which is usually recommended by ODataModelBuilder, automatically infers hierarchy inheritance in the absence of an explicit configuration. Then, as soon as the hierarchy, it will also define properties and property navigation too. This allows you to write less code, focusing on where you deviate from our conventions.