0
votes

Question : How can I force odata decoration to a standard .net core5 WebAPI endpoint?

Details: I already have one controller which i want to add a second controller. No, i dont want/need to create a new controller (I already have a tons of controller for that matter).

The FIRST endpoint is a REAL odata endpoint, with oData decoration/encapsulation :

{ "@odata.context":"ablba",
  "values":[{object},{object},{object}],
  "nextlink":...
   "count":3
}

in the controller :

[HttpGet]
[EnableQuery()]
public IQueryable<MyModel> Get()
{
   return _Dbcontext.MyModels;
}

Odata will allows filtering and all that just like that, but I wont have paging and count.

In order to have full oData endpoint, it seems I am forced to add the entity / controller binding in startup.cs :

private static IEdmModel GetEdmModel()
{ 
   var builder = new ODataConventionModelBuilder();
   builder.EntitySet<MyModel>("NameOfMycontrollers");
   return builder.GetEdmModel();
}

The other endpoint will also have [Enablequery]. Works with $select, $filter, etc.. but WONT RETURN IN ODATA decorations.

so it returns like this :

[{object},{object},{object}]

The problem is that I now have two 'flavor' of api endpoint, and the second one is less flexible (no paging, no count).

I tried adding a second endpoint in odataconventionmodelbuilder, but i will not work. Also, I would really appreciate getting RID of OdataConventionModelBuilder, but article here

using webapi odata without using ODataConventionModelBuilder (not that popular), seems to point in another direction.