问题
Consider I have this OData expression:
http://services.odata.org/northwind/northwind.svc/Categories?
$expand=Products/Category
It will correctly expand the Products.Category
.
Now I want to expand another property too. For example 'Products.Supplier`.
I've tried duplicating the $expand
usage:
http://services.odata.org/northwind/northwind.svc/Categories?
$expand=Products/Category
&$expand=Products/Supplier
but it failed returning this error:
Query parameter '$expand' is specified, but it should be specified exactly once.
回答1:
According to OData ABNF, expand syntax should be:
expand = '$expand' EQ expandItem *( COMMA expandItem )
Which amounts to:
$expand=expandItem1,expandItem2,expandItem3,...
So please try:
http://services.odata.org/northwind/northwind.svc/Categories?$expand=Products/Category,Products/Supplier
For more information, see:
http://www.odata.org/documentation/odata-version-2-0/uri-conventions/#ExpandSystemQueryOption
回答2:
You can also try this syntax for expanding multiple levels:
$expand=Products($expand=Category),...
This works well with MS OData implementation in WebAPI.
来源:https://stackoverflow.com/questions/23977434/how-to-expand-multiple-properties-on-odata