{"id":1844,"date":"2013-01-29T17:58:18","date_gmt":"2013-01-29T17:58:18","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/2013\/01\/29\/getting-started-with-asp-net-web-api-odata-in-3-simple-steps\/"},"modified":"2013-01-29T17:58:18","modified_gmt":"2013-01-29T17:58:18","slug":"getting-started-with-asp-net-web-api-odata-in-3-simple-steps","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/getting-started-with-asp-net-web-api-odata-in-3-simple-steps\/","title":{"rendered":"Getting started with ASP.NET Web API OData in 3 simple steps"},"content":{"rendered":"<p>With the upcoming ASP.NET 2012.2 release, we\u2019ll be adding support for OData to Web API. In this blog post, I\u2019ll go over the three simple steps you\u2019ll need to go through to get your first OData service up and running:<\/p>\n<ol>\n<li>Creating your EDM model <\/li>\n<li>Configuring an OData route <\/li>\n<li>Implementing an OData controller <\/li>\n<\/ol>\n<p>Before we dive in, the code snippets in this post won\u2019t work if you\u2019re using the RC build. You can upgrade to using our latest nightly build by taking a look at <a href=\"http:\/\/blogs.msdn.com\/b\/henrikn\/archive\/2012\/06\/01\/using-nightly-asp-net-web-stack-nuget-packages-with-vs-2012-rc.aspx\">this helpful blog post<\/a>.<\/p>\n<h3>1) Creating your EDM model<\/h3>\n<p>First, we\u2019ll create an EDM model to represent the data model we want to expose to the world. The ODataConventionModelBuilder class makes this this easy by using a set of conventions to reflect on your type and come up with a reasonable model. Let\u2019s say we want to expose an entity set called Movies that represents a movie collection. In that case, we can create a model with a couple lines of code:<\/p>\n<div id=\"codeSnippetWrapper\">\n<div id=\"codeSnippet\">\n<pre><span id=\"lnum1\" style=\"color: #606060\">   1:<\/span> ODataConventionModelBuilder modelBuilder = <span style=\"color: #0000ff\">new<\/span> ODataConventionModelBuilder();<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum2\" style=\"color: #606060\">   2:<\/span> modelBuilder.EntitySet&lt;Movie&gt;(<span style=\"color: #006080\">&quot;Movies&quot;<\/span>);<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum3\" style=\"color: #606060\">   3:<\/span> IEdmModel model = modelBuilder.GetEdmModel();<\/pre>\n<p><!--CRLF--><\/div>\n<\/div>\n<h3>2) Configuring an OData route<\/h3>\n<p>Next, we\u2019ll want to configure an OData route. Instead of using MapHttpRoute the way you would in Web API, the only difference here is that you use MapODataRoute and pass in your model. The model gets used for parsing the request URI as an OData path and routing the request to the right entity set controller and action. This would look like this:<\/p>\n<div id=\"codeSnippetWrapper\">\n<div id=\"codeSnippet\">\n<pre><span id=\"lnum1\" style=\"color: #606060\">   1:<\/span> config.Routes.MapODataRoute(routeName: <span style=\"color: #006080\">&quot;OData&quot;<\/span>, routePrefix: <span style=\"color: #006080\">&quot;odata&quot;<\/span>, model: model);<\/pre>\n<p><!--CRLF--><\/div>\n<\/div>\n<p>The route prefix above is the prefix for this particular route. So it would only match request URIs that start with <a href=\"http:\/\/server\/vroot\/odata\">http:\/\/server\/vroot\/odata<\/a>, where vroot is your virtual root. And since the model gets passed in as a parameter to the route, you can actually have multiple OData routes configured with a different model for each route.<\/p>\n<h3>3) Implementing an OData controller<\/h3>\n<p>Finally, we just have to implement our MoviesController to expose our entity set. Instead of deriving from ApiController, you\u2019ll need to derive from ODataController. ODataController is a new base class that wires up the OData formatting and action selection for you. Here\u2019s what an implementation might look like:<\/p>\n<div id=\"codeSnippetWrapper\">\n<div id=\"codeSnippet\">\n<pre><span id=\"lnum1\" style=\"color: #606060\">   1:<\/span> <span style=\"color: #0000ff\">public<\/span> <span style=\"color: #0000ff\">class<\/span> MoviesController : ODataController<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum2\" style=\"color: #606060\">   2:<\/span> {<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum3\" style=\"color: #606060\">   3:<\/span>     List&lt;Movie&gt; _movies = TestData.Movies;<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum4\" style=\"color: #606060\">   4:<\/span>&#160; <\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum5\" style=\"color: #606060\">   5:<\/span>     [Queryable]<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum6\" style=\"color: #606060\">   6:<\/span>     <span style=\"color: #0000ff\">public<\/span> IQueryable&lt;Movie&gt; GetMovies()<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum7\" style=\"color: #606060\">   7:<\/span>     {<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum8\" style=\"color: #606060\">   8:<\/span>         <span style=\"color: #0000ff\">return<\/span> _movies.AsQueryable();<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum9\" style=\"color: #606060\">   9:<\/span>     }<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum10\" style=\"color: #606060\">  10:<\/span>&#160; <\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum11\" style=\"color: #606060\">  11:<\/span>     <span style=\"color: #0000ff\">public<\/span> Movie GetMovie([FromODataUri] <span style=\"color: #0000ff\">int<\/span> key)<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum12\" style=\"color: #606060\">  12:<\/span>     {<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum13\" style=\"color: #606060\">  13:<\/span>         <span style=\"color: #0000ff\">return<\/span> _movies[key];<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum14\" style=\"color: #606060\">  14:<\/span>     }<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum15\" style=\"color: #606060\">  15:<\/span>&#160; <\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum16\" style=\"color: #606060\">  16:<\/span>     <span style=\"color: #0000ff\">public<\/span> Movie Patch([FromODataUri] <span style=\"color: #0000ff\">int<\/span> key, Delta&lt;Movie&gt; patch)<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum17\" style=\"color: #606060\">  17:<\/span>     {<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum18\" style=\"color: #606060\">  18:<\/span>         Movie movieToPatch = _movies[key];<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum19\" style=\"color: #606060\">  19:<\/span>         patch.Patch(movieToPatch);<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum20\" style=\"color: #606060\">  20:<\/span>         <span style=\"color: #0000ff\">return<\/span> movieToPatch;<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum21\" style=\"color: #606060\">  21:<\/span>     }<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum22\" style=\"color: #606060\">  22:<\/span> }<\/pre>\n<p><!--CRLF--><\/div>\n<\/div>\n<p>There\u2019s a few things to point out here. Notice the [Queryable] attribute on the GetMovies method. This enables OData query syntax on that particular action. So you can apply filtering, sorting, and other OData query options to the results of the action. Next, we have the [FromODataUri] attributes on the key parameters. These attributes instruct Web API that the parameters come from the URI and should be parsed as OData URI parameters instead of as Web API parameters. Finally, Delta&lt;T&gt; is a new OData class that makes it easy to perform partial updates on entities.<\/p>\n<p>One important thing to realize here is that the controller name, the action names, and the parameter names all matter. OData controller and action selection work a little differently than they do in Web API. Instead of being based on route parameters, OData controller and action selection is based on the OData meaning of the request URI. So for example if you made a request for <a href=\"http:\/\/server\/vroot\/odata\/$metadata\">http:\/\/server\/vroot\/odata\/$metadata<\/a>, the request would actually get dispatched to a separate special controller that returns the metadata document for the OData service. Notice how the controller name also matches the entity set name we defined previously. I\u2019ll try to go into more depth about OData routing in a future blog post.<\/p>\n<p>Instead of deriving from ODataController, you can also choose to derive from EntitySetController. EntitySetController is a convenient base class for exposing entity sets that provides simple methods you can override. It also takes care of sending back the right OData response in a variety of cases, like sending a 404 Not Found if an entity with a certain key could not be found. Here\u2019s what the same implementation as above looks like with EntitySetController:<\/p>\n<div id=\"codeSnippetWrapper\">\n<div id=\"codeSnippet\">\n<pre><span id=\"lnum1\" style=\"color: #606060\">   1:<\/span> <span style=\"color: #0000ff\">public<\/span> <span style=\"color: #0000ff\">class<\/span> MoviesController : EntitySetController&lt;Movie, <span style=\"color: #0000ff\">int<\/span>&gt;<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum2\" style=\"color: #606060\">   2:<\/span> {<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum3\" style=\"color: #606060\">   3:<\/span>     List&lt;Movie&gt; _movies = TestData.Movies;<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum4\" style=\"color: #606060\">   4:<\/span>&#160; <\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum5\" style=\"color: #606060\">   5:<\/span>     [Queryable]<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum6\" style=\"color: #606060\">   6:<\/span>     <span style=\"color: #0000ff\">public<\/span> <span style=\"color: #0000ff\">override<\/span> IQueryable&lt;Movie&gt; Get()<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum7\" style=\"color: #606060\">   7:<\/span>     {<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum8\" style=\"color: #606060\">   8:<\/span>         <span style=\"color: #0000ff\">return<\/span> _movies.AsQueryable();<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum9\" style=\"color: #606060\">   9:<\/span>     }<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum10\" style=\"color: #606060\">  10:<\/span>&#160; <\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum11\" style=\"color: #606060\">  11:<\/span>     <span style=\"color: #0000ff\">protected<\/span> <span style=\"color: #0000ff\">override<\/span> Movie GetEntityByKey(<span style=\"color: #0000ff\">int<\/span> key)<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum12\" style=\"color: #606060\">  12:<\/span>     {<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum13\" style=\"color: #606060\">  13:<\/span>         <span style=\"color: #0000ff\">return<\/span> _movies[key];<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum14\" style=\"color: #606060\">  14:<\/span>     }<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum15\" style=\"color: #606060\">  15:<\/span>&#160; <\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum16\" style=\"color: #606060\">  16:<\/span>     <span style=\"color: #0000ff\">protected<\/span> <span style=\"color: #0000ff\">override<\/span> Movie PatchEntity(<span style=\"color: #0000ff\">int<\/span> key, Delta&lt;Movie&gt; patch)<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum17\" style=\"color: #606060\">  17:<\/span>     {<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum18\" style=\"color: #606060\">  18:<\/span>         Movie movieToPatch = _movies[key];<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum19\" style=\"color: #606060\">  19:<\/span>         patch.Patch(movieToPatch);<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum20\" style=\"color: #606060\">  20:<\/span>         <span style=\"color: #0000ff\">return<\/span> movieToPatch;<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum21\" style=\"color: #606060\">  21:<\/span>     }<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum22\" style=\"color: #606060\">  22:<\/span> }<\/pre>\n<p><!--CRLF--><\/div>\n<\/div>\n<p>Notice how you don\u2019t need [FromODataUri] anymore because EntitySetController has already added it for you on its own action parameters. That\u2019s just one of the several advantages of using EntitySetController as a base class.<\/p>\n<p>Now that we have a working OData service, let\u2019s try out a few requests. If you send a request to <a href=\"http:\/\/localhost\/odata\/Movies(2)\">http:\/\/localhost\/odata\/Movies(2)<\/a> with an \u201capplication\/json\u201d Accept header, you should get a response that looks like this:<\/p>\n<div id=\"codeSnippetWrapper\">\n<div id=\"codeSnippet\">\n<pre><span id=\"lnum1\" style=\"color: #606060\">   1:<\/span> {<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum2\" style=\"color: #606060\">   2:<\/span>   <span style=\"color: #006080\">&quot;odata.metadata&quot;<\/span>: <span style=\"color: #006080\">&quot;http:\/\/localhost\/odata\/$metadata#Movies\/@Element&quot;<\/span>,<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum3\" style=\"color: #606060\">   3:<\/span>   <span style=\"color: #006080\">&quot;ID&quot;<\/span>: 2,<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum4\" style=\"color: #606060\">   4:<\/span>   <span style=\"color: #006080\">&quot;Title&quot;<\/span>: <span style=\"color: #006080\">&quot;Gladiator&quot;<\/span>,<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum5\" style=\"color: #606060\">   5:<\/span>   <span style=\"color: #006080\">&quot;Director&quot;<\/span>: <span style=\"color: #006080\">&quot;Ridley Scott&quot;<\/span>,<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum6\" style=\"color: #606060\">   6:<\/span>   <span style=\"color: #006080\">&quot;YearReleased&quot;<\/span>: 2000<\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum7\" style=\"color: #606060\">   7:<\/span> }<\/pre>\n<p><!--CRLF--><\/div>\n<\/div>\n<p>On the other hand, if you set an \u201capplication\/atom+xml\u201d Accept header, you might see a response that looks like this:<\/p>\n<div id=\"codeSnippetWrapper\">\n<div id=\"codeSnippet\">\n<pre><span id=\"lnum1\" style=\"color: #606060\">   1:<\/span> <span style=\"color: #0000ff\">&lt;?<\/span><span style=\"color: #800000\">xml<\/span> <span style=\"color: #ff0000\">version<\/span><span style=\"color: #0000ff\">=&quot;1.0&quot;<\/span> <span style=\"color: #ff0000\">encoding<\/span><span style=\"color: #0000ff\">=&quot;utf-8&quot;<\/span>?<span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum2\" style=\"color: #606060\">   2:<\/span> <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">entry<\/span> <span style=\"color: #ff0000\">xml:base<\/span><span style=\"color: #0000ff\">=&quot;http:\/\/localhost\/odata\/&quot;<\/span> <span style=\"color: #ff0000\">xmlns<\/span><span style=\"color: #0000ff\">=&quot;http:\/\/www.w3.org\/2005\/Atom&quot;<\/span> <span style=\"color: #ff0000\">xmlns:d<\/span><span style=\"color: #0000ff\">=&quot;http:\/\/schemas.microsoft.com\/ado\/2007\/08\/dataservices&quot;<\/span> <span style=\"color: #ff0000\">xmlns:m<\/span><span style=\"color: #0000ff\">=&quot;http:\/\/schemas.microsoft.com\/ado\/2007\/08\/dataservices\/metadata&quot;<\/span> <span style=\"color: #ff0000\">xmlns:georss<\/span><span style=\"color: #0000ff\">=&quot;http:\/\/www.georss.org\/georss&quot;<\/span> <span style=\"color: #ff0000\">xmlns:gml<\/span><span style=\"color: #0000ff\">=&quot;http:\/\/www.opengis.net\/gml&quot;<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum3\" style=\"color: #606060\">   3:<\/span>   <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">id<\/span><span style=\"color: #0000ff\">&gt;<\/span>http:\/\/localhost\/odata\/Movies(2)<span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">id<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum4\" style=\"color: #606060\">   4:<\/span>   <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">category<\/span> <span style=\"color: #ff0000\">term<\/span><span style=\"color: #0000ff\">=&quot;MovieDemo.Model.Movie&quot;<\/span> <span style=\"color: #ff0000\">scheme<\/span><span style=\"color: #0000ff\">=&quot;http:\/\/schemas.microsoft.com\/ado\/2007\/08\/dataservices\/scheme&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum5\" style=\"color: #606060\">   5:<\/span>   <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">link<\/span> <span style=\"color: #ff0000\">rel<\/span><span style=\"color: #0000ff\">=&quot;edit&quot;<\/span> <span style=\"color: #ff0000\">href<\/span><span style=\"color: #0000ff\">=&quot;http:\/\/localhost\/odata\/Movies(2)&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum6\" style=\"color: #606060\">   6:<\/span>   <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">link<\/span> <span style=\"color: #ff0000\">rel<\/span><span style=\"color: #0000ff\">=&quot;self&quot;<\/span> <span style=\"color: #ff0000\">href<\/span><span style=\"color: #0000ff\">=&quot;http:\/\/localhost\/odata\/Movies(2)&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum7\" style=\"color: #606060\">   7:<\/span>   <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">title<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum8\" style=\"color: #606060\">   8:<\/span>   <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">updated<\/span><span style=\"color: #0000ff\">&gt;<\/span>2013-01-30T19:29:57Z<span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">updated<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum9\" style=\"color: #606060\">   9:<\/span>   <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">author<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum10\" style=\"color: #606060\">  10:<\/span>     <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">name<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum11\" style=\"color: #606060\">  11:<\/span>   <span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">author<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum12\" style=\"color: #606060\">  12:<\/span>   <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">content<\/span> <span style=\"color: #ff0000\">type<\/span><span style=\"color: #0000ff\">=&quot;application\/xml&quot;<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum13\" style=\"color: #606060\">  13:<\/span>     <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">m:properties<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum14\" style=\"color: #606060\">  14:<\/span>       <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">d:ID<\/span> <span style=\"color: #ff0000\">m:type<\/span><span style=\"color: #0000ff\">=&quot;Edm.Int32&quot;<\/span><span style=\"color: #0000ff\">&gt;<\/span>2<span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">d:ID<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum15\" style=\"color: #606060\">  15:<\/span>       <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">d:Title<\/span><span style=\"color: #0000ff\">&gt;<\/span>Gladiator<span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">d:Title<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum16\" style=\"color: #606060\">  16:<\/span>       <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">d:Director<\/span><span style=\"color: #0000ff\">&gt;<\/span>Ridley Scott<span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">d:Director<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum17\" style=\"color: #606060\">  17:<\/span>       <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">d:YearReleased<\/span> <span style=\"color: #ff0000\">m:type<\/span><span style=\"color: #0000ff\">=&quot;Edm.Int32&quot;<\/span><span style=\"color: #0000ff\">&gt;<\/span>2000<span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">d:YearReleased<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum18\" style=\"color: #606060\">  18:<\/span>     <span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">m:properties<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum19\" style=\"color: #606060\">  19:<\/span>   <span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">content<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre><span id=\"lnum20\" style=\"color: #606060\">  20:<\/span> <span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">entry<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/div>\n<\/div>\n<p>As you can see, the Json.NET and DataContractSerializer-based responses you\u2019re used to getting when using Web API controllers get replaced with the OData equivalents when you derive from ODataController.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the upcoming ASP.NET 2012.2 release, we\u2019ll be adding support for OData to Web API. In this blog post, I\u2019ll go over the three simple steps you\u2019ll need to go through to get your first OData service up and running: Creating your EDM model Configuring an OData route Implementing an OData controller Before we dive [&hellip;]<\/p>\n","protected":false},"author":449,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[],"class_list":["post-1844","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet"],"acf":[],"blog_post_summary":"<p>With the upcoming ASP.NET 2012.2 release, we\u2019ll be adding support for OData to Web API. In this blog post, I\u2019ll go over the three simple steps you\u2019ll need to go through to get your first OData service up and running: Creating your EDM model Configuring an OData route Implementing an OData controller Before we dive [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/1844","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/449"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=1844"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/1844\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=1844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=1844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=1844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}