Last time I have introduced you to a custom OData extension !summary. But as exciting as it was, the standard .NET Data Client Library does not support it. Why should it right? It does not know about it. To solve this, the eXpress Persistent Objects (XPO) Toolkit now includes a client side library that can understand and work with all the extensions that we make.
The AtomPubQuery<> (similar to the .NET DataServiceQuery<>) will also support all the basic OData operations like $filter, $orderby etc… Let’s see how to use it.
Let’s assume you have an OData service exposing data from the Northwind Database and you want to get top 5 sales broken down by country.
AtomPubQuery<Order> Orders {
get {
return new AtomPubQuery<Order>(
new Uri("http://localhost:54691/Northwnd.svc", UriKind.Absolute),
"Orders",
"OrderID",
this);
}
}var query = from o in Orders
group o by o.ShipCountry into g
orderby g.Count() descending
select new Sale() { Country = g.Key, Total = g.Count() };this.chartControl1.DataSource = query.Take(5).ToList();
This will make the following request:
http://localhost:54691/Northwnd.svc/Orders?!summary=ShipCountry,Count() desc&$top=5
and execute the following query on the server:
select top 5 ShipCountry, count(*) from Orders group by ShipCountry order by count(*) desc
Pretty cool ah? :)
Cheers,
Azret