How to expand multiple properties on OData

两盒软妹~` 提交于 2019-12-21 07:27:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!