Part 01 – OData v4 in ASP.NET WebApi – Introduction

This is a series of blogs detailing my introduction to using OData v4 with C# and ASP.NET WebApi.

What is OData

OData enhances RESTful APIs by adding SQL like syntax if you like, in the URL to add data querying characteristics. It was first engineered by Microsoft however; now it is an OASIS standard. The website gives a much more detailed explanation of what OData is.

OData and ASP.NET WebApi

Microsoft added OData functionality into WebApi starting from OData v1. Since I will be discussing version 4 it is worth quickly noting the different namespaces used for both versions because it is not intuitive and you are likely to see samples on the web which are for version 3.

OData Version 1 to 3

The two namespaces used are:

  • System.Web.Http
  • System.Web.Http.OData

The packages are available in Nuget which have not been updated for a long time.

OData Version 4

The namespace for version 4 is just System.Web.OData. As you can see there is no version in the names and it’s quite easy to add the wrong one.

The package ID in Nuget is called Microsoft.AspNet.OData and again, fairly similarly named to the other Nuget package.

It is worth noting two v4 changes that affect every implementation:

  • MapODataRoute has been changed to MapODataServiceRoute for v4
  • QueryableAttribute has been changed to EnableQueryAttribute  for v4

For more information on the version changes, see the following blog.

There are other namespaces used for the Entity Data Model however; that’s for another blog.