Cannot Enable MapODataRoute for OData Web API Endpoint

I am trying to configure an OData endpoint for my web API service and I cannot solve the MapODataRoute method. In accordance with this tutorial , the following is indicated about the requirements:

ASP.NET and Web Tools 2012.2 Update or Microsoft Web API ASP.NET OData NuGet.

I have installed the current update of ASP.NET and Web Tools 2012.2 (uninstalled the RC version and installed the newest), so my project should be sufficient.

However, I cannot go through the following line of code:

 config.Routes.MapODataRoute("ODataRoute", "odata", model); 

... due to the following exception:

'System.Web.Http.HttpRouteCollection' does not contain a definition for "MapODataRoute" and no extension method "MapODataRoute" that takes the first argument of the type "System.Web.Http.HttpRouteCollection" can (do you miss the use directive or assembly reference?)

I believe that if I install the NuGet package, this message would allow (and it does not really matter for installing it) , but I thought that all OData support was minimized to update ASP.NET and Web Tools 2012.2 ' , therefore not NuGet package required? Does anyone know why MapODataRoute does not allow or which link do I need?

+4
source share
3 answers

From the same lesson:

If you installed the ASP.NET and Web Tools 2012.2 update, the web interface of the project template automatically includes OData packages.

So check your project's nuget packages for odata packages.

You may have installed a new version of ASP.NET and web tools, and then open your old project. I suspect that you do not need to manually add odata packages only if you create the project after installing the ASP.NET update and Web Tools 2012.2.

+2
source

I had to add to install the OData ASP.NET web API from nuget. Then, make sure that you use the System.Web.Http utility statement for the routes to work correctly. Also remember to add routes to WebApiConfig.cs, not RouteConfig.cs

+2
source

For me, none of the above solutions worked.

The MapODataRoute method is MapODataRoute deprecated. The method that worked fine for me was as follows:

 var builder = new ODataConventionModelBuilder(); builder.EntitySet<Supplier>("Suppliers"); builder.EntitySet<Category>("Categories"); builder.EntitySet<Product>("Products"); config.MapODataServiceRoute(routeName: "odata", routePrefix: "odata", model: builder.GetEdmModel()); 

Take a look at another MapODataServiceRoute method. Hope this helps.

+1
source

All Articles