Sunday, April 17, 2011

Exposing POCO as OData Service.

OData – Open Protocol Data aka WCF Data Services.

We all know that using EF(Entity Framework) Data model exposing any relational Data source is very very easy.  But here I am going to show how to expose Plain Old CLR Objects as  OData Service.

1) First Create Empty ASP.NET Web Application.

2) Second we need define or create the Entity Classes and we need to define Primary key using DataServiceKey Attribute for each entity as shown below

image

3) Next we need to create the class which exposes the IQueryable properties which returns the collection of Each entity which we created about. here I have defined the Entity as Contact so my IQueryable properties returns collection of Contacts.

image

image

Next we need to add WCF Data Service Template to this project to host the OData Service with the above Entities.

image

Once we added WCF Data Service Template next we need to specify the Entity class name as shown below.  Next we can set the Access rule for Entity

here I set all Entity have read only access.

image

Now run the service you will see the ODataservice with Two Entity exposed .

image

IF we browse the following URL we get  Contacts details http://localhost:52200/WcfDataService1.svc/MyContacts 

image

Nandri(Thanks)

SreenivasaRagavan

1 comment:

ADmin said...

There are numerous custom writing online directs that will help you compose an effective paper.