提问人:Dave 提问时间:11/14/2023 最后编辑:Brian Tompsett - 汤莱恩Dave 更新时间:11/15/2023 访问量:41
Odata $count 和按实体 ID 搜索在 Dot Net 6 中不起作用
Odata $count and Search by Entity Id Not Working in Dot Net 6
问:
Odata 计数不支持,不确定缺少什么。
https://localhost:7080/odata/Person?$count
Microsoft.OData.ODataException: The value for OData query '$count' cannot be empty.
at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.ThrowIfEmpty(String queryValue, String queryName)
https://localhost:7080/odata/Person?$count=true
Status Code 200 but count is not displayed.
我已经提到了这个问题,并了解到其他人以前也遇到过这个问题,然后这里也遇到了这个问题。
使用软件包
<TargetFramework>net6.0</TargetFramework>
Microsoft.AspNetCore.OData" Version="8.0.10"
Microsoft.EntityFrameworkCore Version="6.0.0"
控制器
[Route("odata/[controller]")]
public class PersonController : ODataController
{
private readonly IPersonRepo _repo;
public PersonController(IPersonRepo repo)
{
_repo = repo;
}
[HttpGet]
[EnableQuery(PageSize = 5)]
//[HttpGet("Person/$count")]
//[HttpGet]
public IQueryable<Person> Get()
{
return _repo.Get();
}
}
程序.cs
static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder builder = new();
builder.EntitySet<Person>("Persons");
return builder.GetEdmModel();
}
builder.Services.AddControllers()
.AddOData(options => options
.AddRouteComponents("odata", GetEdmModel())
.Select()
.Filter()
.OrderBy()
.SetMaxTop(20)
.Count()
.Expand()
);
答: 暂无答案
下一个:.NET Core 基准库
评论
IQueryable
AsNoTracking