是否可以在没有OData端点的情况下使用$ count?

时间:2019-06-21 08:03:19

标签: c# .net asp.net-core .net-core odata

我在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();
}

0 个答案:

没有答案