Brian Vanderbusch
Brian Vanderbusch

Reputation: 3339

OData v2 filter by property of $expanded entity

I am using $expand to enhance an OData SharePoint REST query, and I would like to $filter on one of the properties of the expanded entity. However, I can't find any documentation on the correct syntax for this. I've found a few spots that might suggest using Entity/property, but after trying that, I fail with:

Query:

_vti_bin/listdata.svc/Posts?$expand=Category&$filter=substring(\"Featured Article\",Category/Title) eq false and year(Published) lt " +year+1+ " and month(Published) lt " +month+1+ " or day(Published) lt " +day+1+ " and ApprovalStatus eq '0'&$select=Title,Published,Category,ApprovalStatus&$orderby=Published desc"

Which returns:

syntax error '\"' at position 10.

How would I filter based on the Title of the Category entity, when Category is a high level, and it's Title property is a sub-level?

Upvotes: 9

Views: 23186

Answers (2)

i000174
i000174

Reputation: 1277

The filter on navigation entities is independent of the expand.

Upvotes: 18

Jen S
Jen S

Reputation: 4555

It looks like the problem is the slash-escaped double quote and that you're using substring instead of substringof.

Does it work if you use single quotes instead? Or did you want to literally match the double-quote character? (If that's the case, I think you can just leave the double quote unescaped inside the single quotes)

_vti_bin/listdata.svc/Posts?$expand=Category&$filter=substringof('Featured Article',Category/Title) eq false

or

_vti_bin/listdata.svc/Posts?$expand=Category&$filter=substringof('"Featured Article"',Category/Title) eq false

As an example on a public service, take a look at this query:

http://services.odata.org/Northwind/Northwind.svc/Products?$filter=substringof('Bev', Category/CategoryName) eq true

As far as documentation for the OData query syntax, I recommend taking a look at this page: http://www.odata.org/documentation/odata-v3-documentation/url-conventions

In the filter section there are a fair number of examples you can use for guidance.

Upvotes: 2

Related Questions