Reputation: 3519
I have recently upgraded to .NET 6 Core
Preview and I am experiencing some issues with ODATA. What use to work in .NET Core 3.1
no longer works.
Here is my Startup snippet:
I also believe EnableQueryFeatures()
allows for Count
by default.
services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
}).AddOData(opt => opt
.EnableQueryFeatures()
.AddRouteComponents("odata", GetEdmModel()
);
I have the following Action Method and when called, the count is not returned to the front end.
The pageResult holds a count value, but is not being returned to the front end, when I inspect the result using Chrome DevTools.
[Route("odata/Tasks")]
public PageResult<TaskModel> AjaxListOData([FromQuery]ODataQueryOptions queryOptions)
{
var result = queryOptions.ApplyTo(dataContext.Tasks) as IEnumerable<TaskModel>;
var pageResult = new PageResult<TaskModel>(
result,
null,
count: Request.ODataFeature().TotalCount);
return pageResult;
}
Upvotes: 1
Views: 3504
Reputation: 3519
I resolved the problem by inheriting from ODataController
and not from
Controller
.
Upvotes: 1