Category Archives: odata

February, 2014

Getting started with OData v4 in ASP.NET Web API

Because v4 is almost here!

Since yesterday, the ASP.NET Web stack nightly feed contains the packages supporting OData v4. The package is called Microsoft.AspNet.OData and has a working version 5.2.0 – so I’m guessing this is intended to ship with Web API 2.

It relies on the latest beta of Microsoft.OData.Core. OData v4 is a massive changed compared to v3 – you can read about all of them here.

Continue reading

January, 2013

Easy ASP.NET Web API resource updates with Delta

With or without OData

One of the great features of the Microsoft ASP.NET WebAPI OData package (which you can grab as prerelease from Nuget, and which will soon, in next release cycle, become part of Web API core) is a little dynamic proxy object called Delta<T>.

It allows you to perform ridiculously easy mapping of properties between the model obtained from the database and the model passed by the client – thus facilitating all kinds of update scenarios your application may encounter.

Unfortunately, it will not work for you – unless you commit to ODataMediaTypeFormatter and all the extravaganza related to OData. What if you want to use the traditional API formatters, but still leverage on the power of Delta<T>?

Let’s have a look at how you can perform really smooth full (PUT) and partial (PATCH) updates of your resources in Web API.

Continue reading

August, 2012

Supporting OData $inlinecount with the new Web API OData preview package

Because OData is super useful

OData support in Web API is arguably one of its hottest features. However, it’s support in Web API has been a bumpy ride – initially, OData was supported in a limited way only, and ultimately ended up being yanked altogether from the Web API RTM. It is however stil lpossible to use OData with Web API, only in a slighly different form , as an external NuGet package, which, in its pre-release alpha format was published last Wednesday, along the Web API RTM release.

This package is called Microsoft ASP.NET Web API OData and is a joint effort by Microsoft’s Web API and OData teams. Alex James has written a great introduction to the package, so I recommend reading it.

In the meantime, let me show you how to add $inlinecount support as for the time being, it’s still not provided there out of the box.

Continue reading

June, 2012

Extending your ASP.NET Web API responses with useful metadata

Because heplpful information make it easier for the client

If you ever worked with any API, which, in this day of age, you must have, you surely noticed that in most situations the API response isn’t just the result (requested data), but also a set of helpful metadata, like “total Results”, “timestamp”, “status” and so on.

In Web API, by default, you just serialize your models (or DTO) and such information are not present. Let’s build something which will solve this problem and help you decorate your response with hepful information. This would make it very easy for the client to implement paging, auto-loading scenarios, caching (if you return last modified information) and a lot more.

Continue reading