9th of April 2012 the new version of WCF Data Services was released with number 5.0 and support for V3 OData protocol. You can download this version from here.
You can read more about all new features added to this release of Data Services on WCF Data Services Team Blog
Most important features are
- Spatial types
- Named streams
- Patch support
- Any() All() support
Well there is still missing support for enum types which has at the moment 500 votes on the WCF Data Services wish list.
I started testing new version of Data services with support for Any() and All() linq methods and I found out that quite interesting fact. Any and All methods are supported but only when used in filter syntax for collection properties. When we want to use these method on main entity types we got Not supported exception. Let’s see it in action.
I created two entity types Customer and Order stored in Entity Framework context AppContext
Then I exposed the database context AppContext in Data Service
Important line is 7 where we define to use OData protocol in version 3, so the support for all mentioned features is enabled.
After adding a reference to the service and creating the service context…
…I was surprised that invoking both of following methods…
…notified me with “The method 'Any' is not supported.” and “The method 'All' is not supported.” exceptions. Since I thought that was the default usage of Any and All methods I found the example of usage of these methods on WCF Data Services Team Blog which shows how to use them in a filter expression. According to this I could do following…
which resulted in following queries sent to the Data Service
So it seems that All() and Any() methods are supported only in filter expressions. The result of Any() and All() methods is evaluated on data service side and then used in expression filter. It’s a pity that these methods are not supported on main resource collections, but their can be easily emulated using Count() method which is supported in WCF Data Services also in earlier versions.
We can emulate Any() method like this
which is translated into following query
and returns the count of all Customer entity in Customers collection.
We can also emulate All() method with Count() like this
which results in query