My question is similar to: web-api-odata-inlinecount-not-working
我的问题与web-api-odata- inlinecounit类似
I have installed the following packages:
我已经安装了以下软件包:
<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>
The api is selfhosted with cors and attribute routing enabled.
该api是由启用了cors和属性路由的自托管的。
// used for development purpose only
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
// enables attribute routing
config.MapHttpAttributeRoutes();
The method GetAllProducts of the ProductController:
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;
}
The output by querying
通过查询的输出
http://localhost/api/products
is as follows:
如下:
If I'm appending ?$inlinecount=allpages the output by querying
如果我添加?$inlinecount=通过查询获取输出的所有页面
http://localhost/api/products?$inlinecount=allpages
is as follows:
如下:
During debugging the uri and count are properly set but not mapped in the json response:
在调试uri和count时,适当地设置但未映射到json响应中:
What I'm missing?
我错过什么?
1 个解决方案
#1
9
I found my mistake. By removing the attribute [Queryable] it works just fine.
我发现我的错误。通过删除属性(Queryable),它可以正常工作。
[HttpGet("products")]
public PageResult<ProductViewModel> GetAllProducts(ODataQueryOptions<ProductViewModel> options)
#1
9
I found my mistake. By removing the attribute [Queryable] it works just fine.
我发现我的错误。通过删除属性(Queryable),它可以正常工作。
[HttpGet("products")]
public PageResult<ProductViewModel> GetAllProducts(ODataQueryOptions<ProductViewModel> options)