Using the XamGrid connected to an OData service

[Infragistics] Kiril Matev / Tuesday, August 03, 2010

Many of you have probably heard of the Open Data Protocol (OData) – a Web protocol for querying and updating data. According to the site of the project, the OData protocol is built upon HTTP, AtomPub and JSON to provide a way to connect to a wide range of data sources – applications, services and data stores. It can enable an application to access information from sources as different as relational databases, file systems, content management systems and websites. Additional information on OData can be found here.

This blogpost describes how to connect a Silverlight XamGrid to a hierarchical datasource, exposed as an OData service. The data service used in this case, is one of the services in the list of OData producers, namely the Northwind database. Only reading mode from this source is demonstrated, as the service does not allow any create, update and delete operations to be performed.

Please download the sample project, and follow the source code as we go along. It was built with Visual Studio 2010 and includes the Silverlight XamGrid that shipped with our latest release, 10.2. Take a look at the application screenshot below:

Adding an OData service reference to your project

In order to use an OData service in your application, please follow the instructions below.

Open the Data menu in Visual Studio and select Add New Data Source, as shown below:

Select Service and click Next:

Enter the OData service URL in the address field, and click the Go button. The list of entities in this service will be populated in the left listbox.

Enter a name for the namespace for this service, and click the OK button. Once you do this, types to represent the entities in the service are created in your application.

Binding the Customer table to a XamGrid

Open the Data Sources tool window and click the drop-down button of the Customers table, as shown in the image below:

Click the Customize button and in the dialog window, select the XamGrid as the default control to be used when binding this list of records and click OK. Once you do this, drag the Customers table from the data sources into the XAML designer. This would create a XamGrid, which is bound to the Customers table from the service.

We need to add some C# to retrieve data from the service and feed it into the data source, which is bound to the XamGrid. We’re also using code to retrieve the orders associated with a customer on-demand, and also the order details associated with a particular order. We’re using a dummy order and a dummy order detail objects which prompt the XamGrid to display expander buttons, which, once clicked, remove the dummy order, and insert the records retrieved from the OData service.

Additional Resources

Guidance on modifying and deleting entity data can be found here. Additional guidance on consuming OData feeds can be found here.


In this article, we took a look at how to setup a XamGrid which loads hierarchical data on-demand from an OData service. The attached sample project shows how easily OData feeds can be consumed using the Infragistics XamGrid component. So, in case you’re considering using an OData service, you’re sure to find this article useful.

If you have any questions, do not hesitate to email me at