【发布时间】:2016-01-20 11:47:26
【问题描述】:
当我在 uri 中传递 $inlinecount=allpages 时,我试图让 OData 返回数据库中的实体数。我在 Stack Overflow 中读到我应该返回 IQueryable 而不是 IHttpActionResult,但这并没有解决问题。我也尝试按照 asp.net 网站上的教程进行操作,但也没有给出任何结果。
[EnableQuery(
PageSize = BuildingConstants.BuildingsPerPage,
MaxTop = BuildingConstants.MaxBuildingsPerPage,
AllowedArithmeticOperators = AllowedArithmeticOperators.None,
AllowedLogicalOperators = AllowedLogicalOperators.None,
AllowedFunctions = AllowedFunctions.SubstringOf,
AllowedQueryOptions = AllowedQueryOptions.Filter | AllowedQueryOptions.OrderBy | AllowedQueryOptions.Top | AllowedQueryOptions.Skip | AllowedQueryOptions.InlineCount)]
[ResponseType(typeof(IEnumerable<ListedBuildingResponseModel>))]
public IQueryable<ListedBuildingResponseModel> Get()
{
var buildings = this.buildings
.GetBuildings()
.ProjectTo<ListedBuildingResponseModel>();
return buildings;
}
这是我写的关于 OData 的所有内容。控制器继承ApiController,而不是ODataController。在 Register 方法中,我没有添加任何 OData 路由或模型构建器。 $top、$skip、$orderby 和其他一切工作正常,但 $inlinecount=allpages。有关如何解决问题的任何建议?
【问题讨论】:
-
ODataV4 不是 $count=true 而不是 $inlinecount?
-
“消息”:“不支持查询参数'$count'。”
-
将其添加到允许列表中? “AllowedQueryOptions.Count”。
-
@MarvinSmit 没有这样的查询选项“count”。即使我从属性中删除所有参数并像 [EnableQuery] 一样将其留空,我也会收到相同的错误消息。
-
我发现我已经安装了旧的NuGet包,所以我删除了旧的并安装了OData v4包。现在,我可以使用 count=true,但我仍然没有得到响应中的实体计数。我尝试返回 IHttpActionResult 和 IQueryable,但没有任何成功。
标签: c# asp.net-web-api odata