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
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.
Next we need to add WCF Data Service Template to this project to host the OData Service with the above Entities.
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.
Now run the service you will see the ODataservice with Two Entity exposed .
IF we browse the following URL we get Contacts details http://localhost:52200/WcfDataService1.svc/MyContacts
Nandri(Thanks)
SreenivasaRagavan