c# - 不能将 $count 与 ODataRoute 属性一起使用
问题描述
使用ODataRoute属性会使$count不起作用。
/// Startup.cs
app.UseOData("odata", "odata", GetEdmModel());
static GetEdmModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<User>("User");
builder.EntitySet<User>("Product");
return builder.GetEdmModel();
}
/// MyController.cs
[EnableQuery]
[ODataRoute("User")]
public IQueryable<User> GetUser() => User.GetQuery());
[EnableQuery]
[ODataRoute("Product")]
public IQueryable<Product> GetProduct() => Product.GetQuery());
http://localhost:5901/odata/User(工程) http://localhost:5901/odata/User/$count(不工作)
解决方案
我认为将 AllowedQueryOptions 添加到EnableQuery
属性可能会有所帮助
[EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All )]
[ODataRoute("User")]
public IQueryable<User> GetUser() => User.GetQuery());
推荐阅读
- css - 打印文档中未保留填充
- docker - 从 Docker 内的 gatling 模拟连接到 localhost
- node.js - 无法从 Gitlab 获取 AWS S3 的环境变量
- javascript - 不和谐机器人踢
- node.js - NodeJS mongo 等待/异步函数
- arrays - 如何通过当前 shell(zsh/bash)检测数组起始索引?
- arrays - Angular 9 - 将删除的 li 添加到另一个 ul - 事件绑定
- c - 为什么使用 GMP 时出现分段错误?
- chatbot - 最简单的 Botium 中的两个 REST 端点
- java - 石英带弹簧 5