TechBubbles Microsoft Technology BLOG

OData Querying Options in ASP.NET Web API

What is OData? Open Data Protocol is a web protocol for accessing information via services. It is built upon technologies such as XML and JSON. OData allows you to exposing the data and metadata in a standard way. OData Querying is a query language which allows the clients to send the OData defined parameters in the query string of the request URI. This post discusses the various OData query options that you can use using ASP.NET Web API.

The below class exposing the Entity Framework entity set movies.

image

To enable the OData query options on Entity set add Queryable attribute to Get method

image

To get the movies that released in year 2012 from the database, you can write the below query

image

Using an and operator in querying options, for example to get the movies that released in year 2012 and got the rating greater than or equal to 9

image

If you want to list the movies order by popularity then you can use orderby query option. You can use desc to list the movies in descending order.

image

You can use Top and skip query options as shown below

image

You can add paging support by adding an additional parameter PageSize

image

It then automatically adds the arrows to your page

image

OData Web API supports three formats JSON, XML and ATOM feed. The more samples on this topic can be found here

Reference: Youssef talk from Channel9

About the author

Kalyan Bandarupalli

My name is kalyan, I am a software architect and builds the applications using Microsoft .NET technologies. Here I am trying to share what I feel and what I think with whoever comes along wandering to Internet home of mine.I hope that this page and its contents will speak for me and that is the reason I am not going to say anything specially about my self here.

Add Comment

TechBubbles Microsoft Technology BLOG

Follow me

Archives

Tag Cloud