nik*_*klr 8 c# json asp.net-web-api
我的问题类似于:web-api-odata-inlinecount-not-working
我安装了以下软件包:
<packages>
  <package id="Microsoft.AspNet.Cors" version="5.0.0-rc1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.0.0-rc1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.0.0-rc1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Cors" version="5.0.0-rc1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.OData" version="5.0.0-rc1" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.SelfHost" version="5.0.0-rc1" targetFramework="net45" />
  <package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net45" />
  <package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="5.0.6" targetFramework="net45" />
  <package id="System.Spatial" version="5.6.0" targetFramework="net45" />
</packages>
api是自动主机,启用了cors和属性路由.
// used for development purpose only
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
// enables attribute routing
config.MapHttpAttributeRoutes();
ProductController的方法GetAllProducts:
[Queryable]
[HttpGet("products")]
public PageResult<ProductViewModel> GetAllProducts(ODataQueryOptions<ProductViewModel> options)
{
    //return products.AsQueryable();
    ODataQuerySettings settings = new ODataQuerySettings()
    {
        PageSize = 2
    };
    IQueryable results = options.ApplyTo(products.AsQueryable(), settings);
    Uri uri = Request.GetNextPageLink();
    long? inlineCount = Request.GetInlineCount();
    PageResult<ProductViewModel> response = new PageResult<ProductViewModel>(
        results as IEnumerable<ProductViewModel>,
        uri,
        inlineCount);
    return response;
}
通过查询输出
http://localhost/api/products 
如下:

如果我要附加?$ inlinecount = allpages输出查询
http://localhost/api/products?$inlinecount=allpages
如下:

在调试期间,uri和count已正确设置但未在json响应中映射:

我错过了什么?
我发现了自己的错误.通过删除属性[可查询]它可以正常工作.
[HttpGet("products")]
public PageResult<ProductViewModel> GetAllProducts(ODataQueryOptions<ProductViewModel> options)
| 归档时间: | 
 | 
| 查看次数: | 2330 次 | 
| 最近记录: |