Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

config.MapODataServiceRoute error

I am currently following this guide -> Link to asp.net website

As the guide says I added all the necessary packages via the nuget console and added the necessary usings to the WebApIConfig file. . But when I added the endpoint register method VS gave me an error.

The method I added:

public static void Register(HttpConfiguration config)
    {
        // New code:
        ODataModelBuilder builder = new ODataConventionModelBuilder();
        builder.EntitySet<Product>("Products");
        config.MapODataServiceRoute(
            routeName: "ODataRoute",
            routePrefix: null,
            model: builder.GetEdmModel());
    }

The Error VS gave me:

Error   1   'System.Web.Http.HttpConfiguration' does not contain a definition for 'MapODataServiceRoute' and no extension method 'MapODataServiceRoute' accepting a first argument of type 'System.Web.Http.HttpConfiguration' could be found (are you missing a using directive or an assembly reference?) C:\Users\rvcamp\Desktop\odataTest\odataTest\App_Start\WebApiConfig.cs   29  20  odataTest

I checked the comments of the guide but this error is not mentioned, also I can not resolve the error either. What am I doing wrong?

like image 816
Robin Avatar asked Dec 01 '14 08:12

Robin


3 Answers

I just had this problem. Very frustrating.

I resolved it by adding this in the references at the top of the code page

using System.Web.OData.Extensions;

Right clicking the method did not bring up the resolve menu item either.

Reinstalling everything did no resolve anything for me.

like image 129
Watson Avatar answered Oct 15 '22 06:10

Watson


MapODataServiceRoute is available in Routes Collection, hence below code will do

config.Routes.MapODataServiceRoute(
"odata",
 null, 
GetEdmModel(), 
new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
like image 21
BashaG Avatar answered Oct 15 '22 07:10

BashaG


FOR OData V3

  1. Install Microsoft.AspNet.WebApi.OData
  2. Add using System.Web.Http.OData.Builder; and using System.Web.Http.OData.Extensions;
  3. use like config.Routes.MapODataServiceRoute(...)

FOR OData V4

  1. Install Microsoft.AspNet.OData
  2. Add using System.Web.OData.Builder; and using System.Web.OData.Extensions;
  3. use like config.MapODataServiceRoute(...)

Dont get stuck on WebApi word, they are both for web api.

like image 11
stratovarius Avatar answered Oct 15 '22 07:10

stratovarius