Mike Marks
Mike Marks

Reputation: 10139

Calling Web API via OData implementation to return records that have a foreign key to another record - not working

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):

enter image description here

Here's what I am currently getting when I hit my Web API:

enter image description here

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:

enter image description here

QUESTION How do I get all records, including foreign key records, in my response?

Upvotes: 1

Views: 694

Answers (1)

Slack Shot
Slack Shot

Reputation: 1110

Take a look at the "Expand" method.

Previous Answer Reference

Upvotes: 0

Related Questions