Reputation: 10139
I have two tables in SQL - one is called "ContactDetails" and the other is "Departments". The relationship between the two are 1 to many. 1 ContactDetails record to many Department records.
I am using ASP.NET Web API with OData - this is my first time using OData, so the solution to my question is probably pretty simple (hopefully).
When I make the call to the Get() method on my Web API, the response I get is JSON (as expected), but as you can see, I only get the top level records (the ContactDetails records, and NOT the Departments records). What I obviously want are all the records from ContactDetails, and for each ContactDetails record, have an 'X' number of Department records beneath it. Here's my Get() method (and I'll also note that when I drill into the records here, I do in fact see all of the Department records tied to each ContactDetails record):
Here's what I am currently getting when I hit my Web API:
I suspect the problem may be how I define my ODataModelBuilder/EntitySet/etc. in my WebApiConfig.cs. I hope there's something stupid simple I'm not doing that can be easily pointed out. Here's how that is set up:
QUESTION How do I get all records, including foreign key records, in my response?
Upvotes: 1
Views: 694