0

i am using v4 of oData in an web api.

my get all call returns the entire set (total 3 objects) properly.

http://localhost:9910/api/CommandsRest

enter image description here

but trying to select just the StoreCommand gives me 3 blank objects

http://localhost:9910/api/CommandsRest?$select=StoreCommand

trying to expand StoreCommand gives me StoreCommand but does not gives me its Navigation Properties

http://localhost:9910/api/CommandsRest?$expand=StoreCommand

i want just the StoreCommand property of the main Object with all its Navigation Properties.

Raas Masood
  • 1,475
  • 3
  • 23
  • 61

1 Answers1

1

Try /CommandsRest?$select=StoreCommand&$expand=StoreCommand($expand=DictionaryVariables). This will get you each StoreCommand with the DictionaryVariables property expanded inline.

If you want all of the navigation properties of StoreCommand, you must list them explicitly in the nested expand clause. E.g., $expand=DictionaryVariables,DictionaryNestedSplitVariables,DictionaryMultipleVariables,TabularVariables.

Note that I tested these URIs using in memory data, not MongoDB.

lencharest
  • 2,825
  • 2
  • 15
  • 22
  • Awsome it worked. So i have to do it for the entire graph? No way to get the complete graph simply? – Raas Masood Jan 07 '16 at 00:28
  • Not using query options. If you want a compact way to return a large graph, define on OData function that performs the appropriate MongoDB query. See [Functions & Actions in Web API V2.2 for OData V4.0](http://blogs.msdn.com/b/odatateam/archive/2014/12/08/function-amp-action-in-web-api-v2-2-for-odata-v4-0-type-scenario.aspx) for details. – lencharest Jan 07 '16 at 00:38
  • Since i am using angular's $resource so i have ApiController on the server side but I suppose functions are only possible if i use ODataController. ? – Raas Masood Jan 07 '16 at 00:47
  • I thought you were using an ODataController all along. I'm surprised that `EnableQuery` worked with an ApiController. You can write the equivalent of an OData function on ApiController with a route like "CommandsRest/StoreCommandSubgraph". – lencharest Jan 07 '16 at 01:02