config.MapODataServiceRoute error

后端 未结 6 2506
滥情空心
滥情空心 2021-02-19 03:38

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

相关标签:
6条回答
  • 2021-02-19 04:24

    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.

    0 讨论(0)
  • 2021-02-19 04:24

    I fixed this by opening the package manager console, setting the default project to the project that gave the error message, and then:

    Install-Package Microsoft.AspNet.WebApi.OData
    
    0 讨论(0)
  • 2021-02-19 04:28

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

    config.Routes.MapODataServiceRoute(
    "odata",
     null, 
    GetEdmModel(), 
    new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
    
    0 讨论(0)
  • 2021-02-19 04:29

    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.

    0 讨论(0)
  • 2021-02-19 04:29

    MapODataServiceRoute is extension method. So to use it a reference to its namespace is required. For me it was fixed by referencing:

    using System.Web.Http.OData.Extensions;
    
    0 讨论(0)
  • 2021-02-19 04:44

    If you have upgraded to Microsoft.AspNet.OData 7.0.0 then the namespace you are looking for is:

    using Microsoft.AspNet.OData.Extensions;
    
    0 讨论(0)
提交回复
热议问题