Filter Expressions In OData URIs with Web API

Introduction

OData has now become a very popular way to communicate. In my previous post, we learned create OData services using ASP.NET Web API. As we saw, we can use filter expression in URIs to get the desired results. In this article we will learn more about the filter expression supported by OData.

As we know, keyword '$filter' can be added to end of URI to define filters. It is basically different from C/AL (Client/Server Application) expression. The main reason filter expression is different from C/AL expression is C/AL expressions are applied on Microsoft Dynamics NAV Server tier and filters are applied on Microsoft Dynamics NAV database tier.

With $filter operator, we need to pass property name and its value. The value must enclose in single quotes if value is string type and value must set to true and false for Boolean type.

The following Table contains Filter Expression supported by OData URI.

table
table
table

Points to remember while passing value to filter expression

  • String value must passed in single quotation.
  • Numeric value does not required any delimiters.
  • Date time value must passed in single quotation and must preceded by the word "datetime" for example datetime'2016-04-25T05:16:43.1354695Z'.

Summary

Using filter expression in OData URIs, we can limit the data in result. In this article, I am trying to cover most of filter expressions supported by OData URI.

Read more articles on ASP.NET: