Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OData query with $expand, but empty root $select

Tags:

odata

I've got an OData service with multiple NavigationProperties on a root element. I'd like to perform a query where I don't return any results from the root, e.g. ($top's and metadata removed for brevity)

http://services.odata.org/V4/TripPinServiceRW/People?$expand=Friends($select=FirstName)&$select=null

could return

{
    "value": [{
        "Friends": [{
                "FirstName": "Scott"
        }]
    }]
}

at present, I'm having to specify at least one column in the root-level $select, otherwise all the columns at the root level get retrieved

(i.e. http://services.odata.org/V4/TripPinServiceRW/People?$expand=Friends($select=FirstName)&$select=FirstName )

Is it possible to somehow specify an empty $select list? I can't see an obvious way in the ABNF.

like image 376
Rich Barber Avatar asked Jul 17 '17 10:07

Rich Barber


Video Answer


1 Answers

ah... found it!

If you have an $expand for a NavigationProperty, you can use the NavigationProperty name as the $select, so

http://services.odata.org/V4/TripPinServiceRW/People?$expand=Friends($select=FirstName)&$select=Friends

yields*

{
    "value": [{
        "Friends": [{
            "FirstName": "Scott"
        }]
    }]
}

* $top and metadata removed for clarity

like image 63
Rich Barber Avatar answered Oct 03 '22 00:10

Rich Barber