Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand navigation property on a collection with Client #3130

Open
cbrianball opened this issue Nov 23, 2024 · 2 comments
Open

Expand navigation property on a collection with Client #3130

cbrianball opened this issue Nov 23, 2024 · 2 comments
Assignees

Comments

@cbrianball
Copy link

I've looked over documentation and bugs, but I don't see any example of how to do this.

I am looking to generate the following OData query:
/orders?$expand=items($expand=customer)?

With the Expand method that takes a string, it is simple:
orderQuery.Expand("items($expand=customer)");

How is this accomplished with the overload that takes an expression?
orderQuery.Expand(o => o.Items); is the closest I can get. How do I then expand the Customer navigation property on each of the items?

Here's what I have tried that does NOT work.
orderQuery.Expand(o => o.Items.First().Customer);
orderQuery.Expand(o => ((DataServiceQuery<Item>)o.Items).Expand(i => i.Customer));
orderQuery.Expand(o => (o.Items as DataServiceQuery<Item>).Expand(i => i.Customer));

Any help would be appreciated.

@WanjohiSammy
Copy link
Contributor

@cbrianball Thanks for posting this here. Please look at this doc https://learn.microsoft.com/en-us/odata/client/navigation-properties as we investigate further

@uffelauesen
Copy link
Contributor

uffelauesen commented Dec 3, 2024

@cbrianball One option could be to write it as a projection, something like...

.Select(o => new Order { Items = new DataServiceCollection(o.Items.Select(i => new Item { Customer = i.Customer })) })

OData Client will translate that into a request like /Orders?$expand=Items($expand=Customer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants