我在Odata中的计数功能有问题。
当我使用https://localhost:44327/odata/Customers?$count=true
时,它可以正常使用
https://localhost:44327/Customers/Get?$count=true
个计数将被忽略。
控制器:
[EnableQuery]
[HttpGet]
public IActionResult Get()
{
return Ok(_context.Customers);
}
Startup.cs:
routeBuilder.Select().Filter().Expand().OrderBy().MaxTop(100).Count();
routeBuilder.EnableDependencyInjection();
routeBuilder.MapODataServiceRoute("odata", "odata",GetEdmModel());
private static IEdmModel GetEdmModel()
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
EntitySetConfiguration<CustomerDto> customers = builder.EntitySet<CustomerDto>("Customers");
customers.EntityType.HasKey(entity => entity.Id);
EntitySetConfiguration<OrderDto> orders = builder.EntitySet<OrderDto>("Orders");
orders.EntityType.Name = "Order";
orders.EntityType.Property(p => p.Total).Name = "Check";
return builder.GetEdmModel();
}