question

JayVijayModi-2717 avatar image
0 Votes"
JayVijayModi-2717 asked ChaoDeng-MSFT answered

InvalidOperationException in WebApiConfig File

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();
 builder.EntitySet<Customer>("Customers");
 config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());

And when I hover over the method it says deprecated:

113540-image.png

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


dotnet-aspnet-core-mvcdotnet-entity-framework
image.png (21.1 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have also tried config.Routes.MapODataServiceRoute("odata", "odata", builder.GetEdmModel()); but I'm still getting the same exception.

0 Votes 0 ·

1 Answer

ChaoDeng-MSFT avatar image
0 Votes"
ChaoDeng-MSFT answered

Hi @JayVijayModi-2717 ,

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:https://stackoverflow.com/questions/27224702/config-mapodataserviceroute-error



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,

ChaoDeng


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.