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.
To enable the OData query options on Entity set add Queryable attribute to Get method
To get the movies that released in year 2012 from the database, you can write the below query
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
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.
You can use Top and skip query options as shown below
You can add paging support by adding an additional parameter PageSize
It then automatically adds the arrows to your page
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