Search code examples
odata

SQL Equivalent of IN with odata


I have a collection I am querying using OData syntax. Each of the documents that I am querying looks like this:

{
  id:1,
  name:'test 1',
  storeId: 1
}

Each document can belong to one of 100 stores. I need to get the documents that belong to a specified collection of stores. In SQL, I would do something like this:

SELECT
  *
FROM
  [Document] d
WHERE
  d.[storeId] IN (5, 22, 31, 19, 75)

I think with OData, I need to do something like this:

http://services.odata.org/V4/MyService/Documents?$format=application/json;odata.metadata=full&$filter=storeId [something goes here]

I'm not sure what to put in the [something goes here]


Solution

  • I am afraid ODATA does not have a parallel to SQL IN as of now. (https://issues.oasis-open.org/browse/ODATA-556) . You might need to do something like this:

    $filter=(storeID eq 5) or (storeID eq 22) or (storeID eq 31) or (storeID eq 19) or (storeID eq 75) 
    

    You can probably loop over the array to form the ODATA query.

    Hope this helps you.