Not able to retrieve metadata after api call

Jay Vijay Modi 61 Reputation points
2021-07-12T06:07:19.69+00:00

So I'm following this video on retrieving data using Odata and Entity Framework. I have 5 entities and I have written the following code:

WebApiConfig.cs:

        config.MapHttpAttributeRoutes();  
  
        config.Routes.MapHttpRoute(  
            name: "DefaultApi",  
            routeTemplate: "api/{controller}/{id}",  
            defaults: new { id = RouteParameter.Optional }  
        );  
  
        ODataModelBuilder builder = new ODataConventionModelBuilder();  
        builder.EntitySet<Team>("Teams");  
        builder.EntitySet<Customer>("Customers");  
        builder.EntitySet<Session>("Sessions");  
        builder.EntitySet<SessionEventLog>("SessionEventLogs");  
        builder.EntitySet<RequestCategory>("RequestCategories");  
        config.Routes.MapODataServiceRoute("odata", "odata", builder.GetEdmModel());  

And I have 5 controllers for each entity having following code:

public class SessionController : EntitySetController<Session, int>  
{  
    private CX_DatabaseEntities db = new CX_DatabaseEntities();  
  
    [System.Web.Http.Queryable]  
    public override IQueryable<Session> Get()  
    {  
        return db.Sessions;  
    }  
}  

In the video they use https://localhost:44386/odata/Customer to retrieve the data in JSON format but when I do it I get the following screen:

113676-image.png

Additionally I am getting this popup when I hover over [System.Web.Http.Queryable] in my controller class but don't know if it is affecting anything:

113677-image.png

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,398 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,271 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yijing Sun-MSFT 7,071 Reputation points
    2021-07-12T09:59:59.08+00:00

    Hi @Jay Vijay Modi ,
    As far as I think, I find three problems:

    1. The route need {controller} and {action}.
        config.Routes.MapHttpRoute(  
                       name: "DefaultApi",  
                       routeTemplate: "api/{controller}/{action}/{id}",  
                       defaults: new { id = RouteParameter.Optional }  
                   );  
      
    2. Your request url don't match the route url.
    3. I suggest you could prefix get or post actions.

    Note: QueryableAttribute api is now obsolete. I suggest you use other to replace it.

    Best regards,
    Yijing Sun


    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful