odataorg.github.io icon indicating copy to clipboard operation
odataorg.github.io copied to clipboard

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

Open piyushparate1 opened this issue 7 years ago • 2 comments

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.

piyushparate1 avatar May 10 '18 13:05 piyushparate1

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.

biaol-odata avatar May 10 '18 16:05 biaol-odata

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

piyushparate1 avatar May 11 '18 10:05 piyushparate1