OData / odataorg.github.io

Staging site and collaboration repository for http://www.odata.org
MIT License
63 stars 101 forks source link

$expand not working. Associate/Child records not returned in result #146

Open piyushparate1 opened 6 years ago

piyushparate1 commented 6 years ago

Hi I am facing some issue in $expand odata api.

https://stackoverflow.com/questions/50265218/expand-not-working-associate-child-records-not-returned-in-result

Could you please help.

Thanks.

biaol-odata commented 6 years ago

Hi @piyushparate1: $expand is a widely used system query, therefore likely the issue is due to client code.

From GetModel() and the csdl model generated, Customer entity type have navigation property "ShoppingCart", neither "Product" nor "Products". That is why the first two query doesn't expand the product. As for the third query, "/Customers?$expand=ShoppingCart": from you Get() method,

  1. This duplicated line appears to be incorrect: p1.TrySetPropertyValue("cId", 22);
  2. The "ShoppingCart" navigation property has ContainsTarget = true, and the corresponding datasource is populated by new object[] { p1, p2 } --- doing this way might cause type information lost.

I would suggest debugging this a little bit to make sure the data source is populate correctly; using ContainsTarget = false for shoppingCartNavigation. For further details, you can checkout this tutorial http://odata.github.io/odata.net/#02-03-define-entity-relations, which contains some samples.

piyushparate1 commented 6 years ago

Thank you so much @biaol-odata, for your response. I am new in this, didnt knew that - only navigation property can use in url.

1 - After spending 4days on the same code snippet, I kind of missed that duplicate lines. I fixed that code.

2 - Updated the ContainsTarget property, as well as the way i am assigning child record.

Still it doesnt returning the child record. Do we need to add one more controller to handled child records?

My code is in https://github.com/piyushparate1/SampleODataUntyped