Last week I got the following question:
“I have an OData service that returns a set of Portfolios. Each portfolio also has a list of Sectors, a list of Technologies and a list of Customers. How can I query this OData feed and get all the results back in one request?”
To achieve this we need to use the Expand() keyword
Here is a sample how to do this in Linq;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from p in Portfolio | |
.Expand("Sectors") | |
.Expand("Technologies") | |
.Expand("Customers") | |
select p |
And here is the resulting url that returns the same results:
http://odatasample/Portfolio()?$expand=Sectors,Technologies,Customers