InvalidOperationException in WebApiConfig File

Jay Vijay Modi 61 Reputation points

I'm following this video on creating service stack for Entity Framework and the video uses config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel()); in their WebApiConfig file.
I am using the same piece of code in my project and I'm getting this error:

System.InvalidOperationException: 'The complex type 'ClassLibrary1.Session' refers to the entity type 'ClassLibrary1.Customer' through the property 'Customer'.'

for this piece of code:

var builder = new ODataConventionModelBuilder();  
config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());  

And when I hover over the method it says deprecated:


So what do I use here to get the same output of the video.

Microsoft Technologies based on the .NET software framework.
3,348 questions
A set of technologies in the .NET Framework for building web applications and XML web services.
4,146 questions
{count} votes

Accepted answer
  1. Chao Deng-MSFT 796 Reputation points

    Hi @Jay Vijay Modi ,

    What version of OData are you using?

    FOR OData V3:

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

    FOR OData V4:

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

    You can refer to this article:

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,


    0 comments No comments

0 additional answers

Sort by: Most helpful