Hot on the hills of Visual Studio 2013, new enhancements of ASP.NET Web API (Web API 2) and ASP.NET MVC (MVC 5) were made. Improving Web API developers added features for OData which weren’t included in the first release of the ASP.NET Web API Data made in June 2013. Four OData capabilities now are the part of the Web API (such as $expand, $select, $value along with batch updates).
Some words about the basics
Open standard specification OData is meant for using CRUD-centric (Create – Read – Update – Delete) data services over HTTP. It corresponds to the majority of the design guidelines of the REST architectural style and provides easy path for unperplexed implementation of data services and their usage on different modern development platforms.
Two main OData features are provided for these tasks – OData URL query syntax and the full OData communication protocol. The first enables performance of rich queries from the client. It foresees sorting, filtering and paging. The full OData communication protocol consists of OData message formatting standards along with supported operations and calling patterns used for CRUD operations via OData.
Besides, there are supported OData services for ASP.NET Web API in Web API OData. They involve support for the OData query syntax which is suitable for all Web API services demonstrating IQuerable collection results via GET operations. OData protocol compliant service is implemented too. This service provides support of full CRUD operations performed on an object model comprehending relationships between the entities.
The changes made to the Web API 2
The new OData capabilities are implemented in the manners which expels the need of changes in the code, if Web API OData have been used since the release in June 2012. The features are simply launched when developers add the ASP.NET Web API 2 OData NuGet package as an update. Concerning the batch operation a trivial change is made to routing initialization and then you are free to run with the capabilities.
Due to adding the features through NuGet packages mentioned capabilities are backward compatible to .NET 4.0. As soon as the NuGet is installed, $select and $expand start their work automatically without interfering into your code. If you wish to get a single property value you are to run an accessor method for chosen property to the controller that comprises entity key and has naming convention of Get<PropertyName>(). Dispatching of calls will be made by the OData routing.