Introduction
OData (Open Data Protocol) is an open protocol for sharing the data. There is built-in support of OData in Web API. OData URI is also support the filter expression.
One of the common requirements for web application is displaying partial data from a large result set. For example user may able to browse the 50 records from 1 lakh of records and the next 50 records will be populated when the user is in the next page. If we display all records in single page, it would affect performance significantly.
We can implement Paging in two ways. Web API has built-in support for both option client and server driven paging.
Client Driven Paging
The client decides how many records contained by the page and tell it to server for page of size.
Server Driven Paging
Here client is just sending requests for the collection of entities and server returns partial results like which is used to retrieve more results
Client - Driven Paging
As we know, we can define the parameters with OData URI to modify the OData query. Client sends these parameters in the query string of URI. Client driven paging can be implemented with the OData query.
OData Query Options
Following OData query options supported by Web API.
| Options | Description |
| $orderby | Used for sorting |
| $select | Select which properties are included in result set |
| $skip | How many record wants to skip |
| $top | How many record wants to retrieve |
| $filter | Filter the result set |
| $expand | Expand the related entity |
| $inlinecount | Used to include total record count in response |
As query option has keyword $top and $skip. $top is used tell server how many records client wants. We can turn on the client query support with "Queryable" or "EnableQuery" attribute defined on top of action method of Web API.
Example
I have taken same example which was used in my previous article. In this example I have created in-memory data source and configured the end point. In data source, I have added some more entries.
- /// <summary>
- /// In memory Data source
- /// </summary>
- /// <returns></returns>
- public List<TestData> CreateTestData()
- {
- List<TestData> data = new List<TestData>();
- data.Add(new TestData { Id = 1, Name = "Jignesh", Role = "Project Manager" });
- data.Add(new TestData { Id = 2, Name = "Tejas", Role = "Architect" });
- data.Add(new TestData { Id = 3, Name = "Rakesh", Role = "Lead" });
- data.Add(new TestData { Id = 4, Name = "Hiren", Role = "Developer" });
- data.Add(new TestData { Id = 5, Name = "Pooja", Role = "Developer" });
- data.Add(new TestData { Id = 6, Name = "Keyur", Role = "Developer" });
- data.Add(new TestData { Id = 7, Name = "Ashish", Role = "Developer" });
- data.Add(new TestData { Id = 8, Name = "Parth", Role = "Developer" });
- data.Add(new TestData { Id = 9, Name = "Manish", Role = "QA" });
- data.Add(new TestData { Id = 10, Name = "Manisha", Role = "QA" });
- data.Add(new TestData { Id = 11, Name = "Urmi", Role = "QA" });
- data.Add(new TestData { Id = 12, Name = "Bharat", Role = "QA" });
- data.Add(new TestData { Id = 13, Name = "Varun", Role = "QA" });
- data.Add(new TestData { Id = 14, Name = "Komal", Role = "QA" });
- data.Add(new TestData { Id = 15, Name = "Dhaval", Role = "QA" });
- data.Add(new TestData { Id = 16, Name = "Chirag", Role = "Project Manager" });
- data.Add(new TestData { Id = 17, Name = "Devid", Role = "QA" });
- data.Add(new TestData { Id = 18, Name = "Vivek", Role = "Developer" });
- data.Add(new TestData { Id = 19, Name = "Purvi", Role = "Architect" });
- data.Add(new TestData { Id = 20, Name = "Denish", Role = "Developer" });
- return data;
- }

Vivek KumarPosted Aug 20, 2016, 4:18 PM
Nice one
Munesh SharmaPosted May 27, 2016, 2:23 PM
nice
Renish PatelPosted May 9, 2016, 4:03 PM
Nice Article.Good one
Amit DavePosted May 3, 2016, 10:35 AM
Keep up the Good work!
Humayun Kabir MamunPosted May 3, 2016, 2:46 AM
Nice...
Sonu ChaudharyPosted May 2, 2016, 5:57 AM
Thanks for sharing
NitinPosted May 1, 2016, 1:48 PM
Nice
Munesh SharmaPosted May 1, 2016, 11:11 AM
nice article
Kuppurasu NagarajPosted Apr 30, 2016, 2:18 PM
Nice Sharing..
Rahul Kumar SaxenaPosted Apr 30, 2016, 1:49 PM
Good Show
Vignesh ManiPosted Apr 30, 2016, 12:45 PM
Nice one
Vivek KumarPosted Apr 30, 2016, 8:57 AM
Good one
Debasis SahaPosted Apr 30, 2016, 4:32 AM
Nice one..