问题
This is related to Azure's recently launched search service that is currently in preview form. I'm trying to figure out how to use OData's filter with collections. I know that I can do this:
$filter=Products/any(p: p eq 'WidgetA')
which will filter the Products collection by WidgetA. What I am trying to figure out is how to specify WidgetA OR WidgetB. I know that I can do this:
$filter=Products/any(p: p eq 'WidgetA') or Products/any(p: p eq 'WidgetB')
but thought there must be a more elegant or shorter way of doing this.
回答1:
Unfortunately, there is no as far as I know. The operator that addresses your requirement is 'in' but there is no in the protocol: http://docs.oasis-open.org/odata/odata/v4.0/os/part2-url-conventions/odata-v4.0-os-part2-url-conventions.html
One more thing: there should be a property follows the range variable:
http://host/service/Orders?$filter=Items/any(d:d/Quantity gt 100)
in your case it should be "p/Name eq 'WidgetA'" or some other properties.
来源:https://stackoverflow.com/questions/25673213/filter-and-collections-in-odata