By default, the server will represent any associated object in a JSON response using the reference convention. For example, suppose a request for a Customer object:
will return a JSON response like this:
Note the associated Country is represented as a reference (Country with Id = 10). This is very handy when using Delphi client (TXDataClient) or even non-Delphi client where you just want to modify the country reference without needing to retrieve the whole object.
However, in some cases you might want to have the full Country object inline. With the $expand query option you can explicitly indicate which associated properties you want to be inline:
Response will be:
$expand applies to both single association and lists. It also forces any server-side proxy to be loaded, so even if Country is lazy-loaded, $expand will retrieve the entity inline. XData optimizes this retrieval process by forcing the proxy to be loaded eagerly in a single SQL statement (except for lists).
Expanding blob properties
You can also use $expand to ask for the server to bring blob content inline in object representation. By default, blob properties will be represented as a proxy reference:
If you want the blob content to be retrieved together with the object, you can ask to $expand the property:
Then the blob content will be inline as a base64 string:
Expanding multiple properties
You can expand multiple properties by separating them using comma. The following example expands properties Customer, Seller and Products:
You can also expand subproperties (deeper levels) by using slash to specify subproperties. The following example expands property Customer and also the Country property of such customer (and Seller) property: