Introducing Simple.Data OData provider

Mark Rendle’s Simple.Data has quickly become a popular choice to retrieve data from various data sources. The number of Simple.Data providers includes today SQL Server, Oracle, Mysql, MongoDB and others. When I saw Simple.Data in action, I became enthusiastic about extending its list of providers with OData. I believe dynamic nature of Simple.Data matches very well RESTful nature of OData. Currently Visual Studio offers creation of a client context from an OData feed using “Add Service Reference” dialog which treats an OData service like it was a traditional SOAP service. This is unfortunate because OData communication does not need an interface proxy: communication is based on HTTP methods and can be implemented without context creation ceremony.

Welcome to Simple.Data OData provider! When I asked Mark Rendle on Twitter if he had thought about writing a Simple.Data OData provider, he replied that he was working on Windows Azure table provider that also uses OData protocol, and he offered me to join the project and focus on generic OData client implementation. This gave me an exciting opportunity, and today I am glad to announce that Simple.Data OData provider preview is available, and it’s Nuget feed is published.

Simple.Data OData provider is hosted at GitHub. The source code based is shared by OData and Azure provider implementation, but the Nuget packages are different.

Getting started with Simple.Data OData provider

The easiest way to start using Simple.Data OData provider is to install it’s Nuget package. In Visual Studio open Package Manager console and type the following:

Install-Package Simple.Data.OData

You will see output similar to this:

Attempting to resolve dependency 'Simple.Data.Core (≥'.
Successfully installed 'Simple.Data.OData 0.1.1'.
Successfully added 'Simple.Data.OData 0.1.1' to SimpleODataTest.

In the source file where you will be using OData provider import namespaces:

using Simple.Data; 
using Simple.Data.OData;

Create an instance of dynamic database object that will be used to communication with OData feed:

dynamic db = Database.Opener.Open("");

Now you can start retrieving data from the OData server using Simple.Data syntax:

var package = db.Packages.FindByTitle("Simple.Data.OData"); 

Reading data using Simple.Data OData provider

package = db.Packages.FindByTitleAndVersion("Simple.Data.OData", "");

Find multiple results:

IEnumerable<dynamic> packages = db.Packages.FindAllByTitle("Simple.Data.OData");
packages.ToList().ForEach(x => Console.WriteLine(x.Title + " " + x.Version));

packages = db.Packages.FindAll(db.Packages.Version == "");
packages.ToList().ForEach(x => Console.WriteLine(x.Title + " " + x.Version));

Select column subset:

IEnumerable<dynamic> packages = db.Packages

Limit number of results using Skip and Take:

IEnumerable<dynamic> packages = packages = db.Packages

packages = db.Packages

Retrieve results in specific order:

IEnumerable<dynamic> packages = db.Packages

What’s next

OData provider already supports Insert,Update and Delete operations (more about it in a next blog post), but it does not support associations. The implementation of the new functionality requires some changes to Simple.Data.Core library that is on its way.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s