Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I am currently working on (basically researching) on OData. So I am new to open data protocol.

And i want to use this facility with my web api project. As per the requirement i want to fetch the relational data. Basically a data from Parent and Child tables.

Everything seems to be working fine. But as i fetch this relational data it gives me only data from the parent table and not from the child table. (May be because of self referencing. )

Does any one has any idea about how to resolve this issue ?

And if i create a ViewModel and feed data into that than it gives me 406: not acceptable.
Posted

1 solution

You would need to configure a route to your odata endpoint. This is done inside the App_Start\WebApiConfig.cs file in the Register method. Use the following code to add an entity model and a route:
C#
ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<product>("ProductSet");

Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel();
config.Routes.MapODataRoute("ODataRoute", "odataSuffix", model);
</product>


Note that the name of your controller should match the name of EntitySet. In this example the name of entity set is ProductSet so your controller must be called ProductSetController.

Once this is configured the Product model can be accessed by the following url:
http://hostname:portNumber/odataSuffix/ProductSet
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900