Let's say that we have a data service exposing all of Northwind. We can get all customers in the database by accessing this URL.
That could be more data than we wanted. Let's say we only care about customers in London. We can use the $filter query option to get all customers that match this condition by accessing this URL.
/Customers?$filter=City eq 'London'
(I’m shortening and unescaping such URLs for readability; we actually follow standard URI conventions and the URI you’ll see will be something like http://localhost/WebDataService1.svc/Customers?$filter=City%20eq%20'London')
What can go in a $filter? The most basic thing to do is to test properties of the resources we're returning, which you can access simply by name, like we have done above. Literals for things like strings and numbers use the same syntax as in the key portion (see my last post and the original URL post for more details).
To actually test for a condition, you can use comparison operators, which look a lot like the symbolic ones you'd expect in C# but use short mnemonics to make them easier to write and not have to deal with escaping/unescaping in the URL.
So all of these are valid URLs:
To include more than one condition, you can use 'and', 'or' and of course 'not'.
To group conditions logically, you can use parenthesis.
Today we don’t support operations on collections, which has two practical points.
Next time, more on what you can put in a $filter.
This post is part of the transparent design exercise in the Astoria Team. To understand how it works and how your feedback will be used please look at this post.
PingBack from http://geeklectures.info/2008/01/10/filter-query-option-in-adonet-data-services/
Marcelo from our team has posted a nice write up detailing how the $filter query string operator works
While the syntax described for filter in the previous post allows you to do some nifty things, there