Skip to main content

ADO.NET Data Services

In Traditional web applications, you request a page and the the server, process the request, makes some database calls if needed and put your data and HTML together and pass on to the client.This model has now changed with RIA, using AJAX, Silverlight and others

Take for an example a hotel reservation page that uses AJAX for user interactions. Maybe the intital page loads with all available countries in a combo box. and when the user selects a country, all the hotels for that country is retrived through a AJAX call.

Now, this is different form the typical web model, initially by requesting this page, the server send out HTML and presentation logic (javascript in this case for AJAX) to the client. The request for the hotels for a particular country is a pure data call, where only data flows in the form of XML.

This example was just used to demonstrate the change from the traditionl web model, but you would find a lot more pure data calls then just one (like in this case) in real world web applications.

The ADO.NET Data Serveice (formally called Astoria), helps developers in this area, providing a simple but yet a powerful way to expose data centric operations.
Data services, exposes your data as a RESTful services, so that your data could be accessed as a web resource, i.e through URLs.
As RESTful services support the CRUD operations, you can use HTTP verbs like POST to insert data, PUT to update data, GET to retrive data and DELETE to delete data.

for an example, you can access all the hotels of a specific country like this,

Tthis would retrive all the hotels in Sri Lanka. The Country and Hotel in the above URL are conceptual entites in your data source of your domain.

The data from the data services can be retrived in multiple represnetation,presently the data service framework exposes data in JSON, ATOM and in POX (plain old XML).

Building a ADO.NET data services is simple. Listed below are some of the common steps when creating a ADO .NET data service.

1) Create a Entity Data Model(EDM) representing your data. The EDM was introduced part of the ADO.NET Entity Framework.
2) Create a data service class representing your entites created in the EDM.

So, Lets make this concept more concrete, lets say my database contains two table, Country and Hotel. I can create an EDM model pointing to my database.
Now, my generated model would contain 2 conceptual entities called Country and Hotel.
Next step, I create a data service (called hotelservice.svc ) based on the generated EDM model.
Now I can access all the Countries using the URL
You can see that I am actually pointing to the entity that is in my EDM model, which in turns points to the Country table.
I can access the Country with the name India like this (country name is my primary key)

I can list all the Hotels for the country India like this
and so on..

What makes the ADO.NET data services very simple is that, you dont need to write code for each and every operations you provide, think about it, you would have to write a service opeartion, write your SQL query, connect to a database, execute it, get the result set, convert it into a format your client understands and send it back to the client, but with data services, all this is done for you, only things
you might have to do when exposing data in a database would be to create an EDM model and create a data service (just a few line of code, minimum of 2 lines) and the rest is done by the framework for you.

You can expose data that does not inherantly come from databases, by exposing the data to the data service framework through the IQueryable interface (introduced with LINQ).
The point of this artical is just to introduce ADO.NET data services and not to give you an example of a working sample, you can find more about how to create data services here.

What makes data services easy to use is there capabilty to provide common functionalites like filtering,sorting, ordering of data and paging, through request parameters in the url, for an example, If I want all the 3 star hotels in Sri Lanka, I can send out a request like this,
http://www.hotelservice.svc/Country(SriLanka)/Hotels?$filter=Type eq '3star'

The other operations are as easy as this, the framework even provides a parameter called $value, that allows you to retrive only data without the surrounding XML markup.

You can also restrict the types of operations that users can do on the service, like providing user only with read only access to your data.
You can download the CTP version of the ADO.NET here...try it out.


  1. So thats great I got some idea for the project ...thanks bro

  2. thanks bro, i got some idea ,,,nice work


Post a Comment

Popular posts from this blog

Hosting WCF services on IIS or Windows Services?

There came one of those questions from the client whether to use II7 hosting or windows service hosting for WCF services. I tried recollecting a few points and thought of writing it down.
WCF applications can be hosted in 2 main ways- In a Windows service- On IIS 7 and aboveWhen WCF was first released, IIS 6 did not support hosting WCF applications that support Non-HTTP communication like Net.TCP or Net.MSMQ and developers had to rely on hosting these services on Windows Services.With the release of IIS 7, it was possible to deploy these Non-Http based applications also on IIS 7. Following are the benefits of using IIS 7 to host WCF applications
Less development effort
Hosting on Windows service, mandates the creating of a Windows service installer project on windows service and writing code to instantiate the service, whereas the service could just be hosted on IIS by creating an application on IIS, no further development is needed, just the service implementation is n…

Task based Asynchronous pattern, Async & Await and .NET 4.5

One of the key features in .Net 4.5 is to write asynchronous programs much easier. So if I was to write asynchronous programs in .Net 2.0/3.5, I would either follow the event based model or the callback based model. For an example, a synchronous method that does intensive work (say the DoWork()) can be made asynchronous by using the following patterns
1) Implementing the IAsyncResult pattern. in this implementation, 2 methods are exposed for the DoWork() synchronous method, the BeginDoWork() and the EndDoWork() method. The user will call the BeingDoWork() passing in the required parameters and a callback of the delegate type AsyncCallback(IAsyncResult). The BeginDoWork() will spawn a new thread a return control back to the user. Once work is completed in the spawned method, as a last step, it will call the inform the AsyncResult implementation, which in turns will call the EndDoWork() (which is the callback that was passed in to the BeginDoWork()).
2) Implementing the event pattern. Her…

MEF (Managed Extensibility Framework), .NET 4, Dependency Injection and Plug-in Development

Almost after .Net 4 was released I remember reading about MEF (Managed Extensibility Framework), this was a framework for developers to compose their application with required dependencies. At first this looks like the Unity Container used for dependency injection, but MEF is much more than a dependency container but there is nothing stopping you from using MEF as a dependency injector.I remember around 5 years back when I was in a project that created a framework that allows developers to plug-in there modules as WinForm screens. The developer would create a set of screens with the intended functionalities and the drop this component in the bin folder of the framework and then will move on to do some painful configurations for the framework to pick up the module. Dropping the component into the bin folder and doing a bit of configuration is all that s needed for the framework to pick up display the screens. Typically, the configurations would also contain metadata about the screen.Al…