I have been hearing the term OData a lot lately but I had no idea what it really was. So I did a little searching and stumbled upon odata.org. OData or the Open Data Protocol is a new format for sharing data on the web using REST (Representational State Transfer). The text book definition of OData from the website is as follows:
The Open Data Protocol (OData) is an open protocol for sharing data. It provides a way to break down data silos and increase the shared value of data by creating an ecosystem in which data consumers can interoperate with data producers in a way that is far more powerful than currently possible, enabling more applications to make sense of a broader set of data. Every producer and consumer of data that participates in this ecosystem increases its overall value.
At the heart, OData is really just producing an ATOM or JSON payload. Since ATOM and JSON are universally known, OData is not tied in any way directly to the .NET family of languages. OData already has consumer libraries which can be used for the following programming languages and devices:
Windows Phone 7 Series
iPhone (Objective C)
If you have previously implemented services using the the "Astoria" protocol, ADO.NET Data Services or WCF services then you can now tell your customers that you have OData support. Apparently the Microsoft marketing team has strategically renamed the product again just to confuse the hell out of everybody.
Finally, as proof that Microsoft "eats their own dog food", you will find Open Data Protocol support in SharePoint Server 2010, Excel 2010 (through SQL Server PowerPivot for Excel), Windows Azure Storage, SQL Server 2008 R2, and Visual Studio 2008 SP1. In addition, the Microsoft developer teams have been working hard on building some real world examples. What better place to showcase the OData protocol than nerddinner.com!
The Nerd Dinner Example
If you have any interest in ASP.NET MVC, then chances are that you have the Nerd Dinner book on your bookshelf. Therefore its no surprise that the Nerd Dinner example has been updated to include an OData service.
Up to this point, we have been talking about a lot about OData by throwing around acronyms and technical jargon. However, if my site supports OData what does it really mean? Well, perhaps it will help if we first talk about something that we are all familiar with as .NET Developers.....LINQ. LINQ or Language Integrated Query is a library that was written to simplify the process of querying object collections for data by using a SQL-Like syntax. Since, OData can be deserialized into an object collection we can obviously use LINQ to query it. Therefore, once an OData service is exposed we can read and write data the same way the we use LINQ to SQL to update a database table! So to summarize, a third party can reference your OData service by URL (just like we have done for years with web services). The client library, will then read the descriptors created by the OData service to generate an object model. Finally, you can use LINQ to query the object collections exposed by the service.
In the screenshot below, I used LINQPad 4 to create a data connection to the nerddinner.com website. Then I issued a query to find all the dinners that are taking place in my home state of New York. You have to admit, this is very powerful!