Blogs

The One With

OData Provider for XPO – GroupBy(), Count(), Max() and More…

     

OData + !summary ExtensionsLast 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();
 
OData feed bound to a Chart Control 

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

Published Aug 15 2010, 01:13 PM by Azret Botash (DevExpress)
Filed under: , , ,
Technorati tags: XtraCharts, XPO, OData, ExMedia
Bookmark and Share

Comments

No Comments
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.