Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter out empty arrays/lists in OData v4 Query?

Tags:

odata

In OData V4, you are able to filter out empty strings as follows:

OData/v4/2.0/Case?filter=Date ne null

or OData/v4/2.0/Case?filter=Date ne ''

I, however, have an OData query which requires filtering out an empty array/list of names (empty would be: [] so an empty list). Lists cannot be filtered out in the same way:

OData/v4/2.0/Case?filter=Names ne null

does not work. Same goes for the other method.

Is there another way to filter out lists like this Names one?

Thanks in advance

like image 565
thelegend27 Avatar asked Dec 22 '22 21:12

thelegend27


2 Answers

...Or you can use any() operator.

The any operator without an argument returns true if the collection is not empty.

docs

OData/v4/2.0/Case?$filter=Names/any()

like image 141
donMateo Avatar answered Dec 25 '22 10:12

donMateo


If your service supports this operation, you can use the $it literal:

OData/v4/2.0/Case?filter=$it/Names/$count gt 0
like image 20
corschdi Avatar answered Dec 25 '22 09:12

corschdi