• Fabian Wetzel
  • 2012-12-03
  • 1 min. read

OData is like Linq over HTTP

…and it is easy to setup as well! If you already have an Entity Framework DataContext in your solution, you just need to add a WCF Data Service:

In there, you have to do two easy steps:

  • Insert your DataContext type as the generic type inside the base class.
  • Apply AccessRules to entities you want to share.
    That is everything you need to do to get the server running! Awesome!

You can now do standard HTTP request to query your service or you can do “add service reference” in your client app and get generated types as you are used to.

You can then do your Linq queries!

The shown query translates to this HTTP get request (broken in multiple lines for readability):

http://localhost:51985/odataFuel.svc/FuelReadings()?
$filter=KmStand ge 33000 
&$orderby=KmStand&$skip=0
&$top=1

It is easy to see the translated Linq parts inside the URL. This URL is testable through a web browser and returns readable xml:

If you setup write access on your server-side, you can also update the data! The data modification permissions are very fine-grained. You can configure it, to allow new inserts, but no updates or deletes for example:

Server:

Client:

Working with OData is easy and fun :-)