Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 在仍然分页的情况下,如何使用OData/web api查看总的匹配请求?_Asp.net_Asp.net Mvc_Asp.net Web Api_Odata - Fatal编程技术网

Asp.net 在仍然分页的情况下,如何使用OData/web api查看总的匹配请求?

Asp.net 在仍然分页的情况下,如何使用OData/web api查看总的匹配请求?,asp.net,asp.net-mvc,asp.net-web-api,odata,Asp.net,Asp.net Mvc,Asp.net Web Api,Odata,当利用托管在不同服务器上的Web Api端点时,进行分页以避免过度序列化和反序列化的最佳方法是什么,同时仍然能够看到Get请求中找到的匹配项的总数 Web Api: [Queryable] public IQueryable<Customer> Get(string input) { return _repo.GetCustomers(input).AsQueryable(); } HttpResponseMessage response = client.GetAsync

当利用托管在不同服务器上的Web Api端点时,进行分页以避免过度序列化和反序列化的最佳方法是什么,同时仍然能够看到Get请求中找到的匹配项的总数

Web Api:

[Queryable]
public IQueryable<Customer> Get(string input) {
    return _repo.GetCustomers(input).AsQueryable();
}
HttpResponseMessage response = client.GetAsync("api/customer?input=test&$top=2&$skip=0").Result; // test string
if (response.IsSuccessStatusCode) {
    CustomerSearchResultViewModel resultViewModel = new CustomerSearchResultViewModel();
    resultViewModel.Customers = response.Content.ReadAsAsync<IEnumerable<Customer>>().Result.ToList();
    resultViewModel.TotalResults = resultViewModel.Customers.Count;
}
[可查询]
公共IQueryable获取(字符串输入){
return_repo.GetCustomers(input.AsQueryable();
}
控制器代码:

[Queryable]
public IQueryable<Customer> Get(string input) {
    return _repo.GetCustomers(input).AsQueryable();
}
HttpResponseMessage response = client.GetAsync("api/customer?input=test&$top=2&$skip=0").Result; // test string
if (response.IsSuccessStatusCode) {
    CustomerSearchResultViewModel resultViewModel = new CustomerSearchResultViewModel();
    resultViewModel.Customers = response.Content.ReadAsAsync<IEnumerable<Customer>>().Result.ToList();
    resultViewModel.TotalResults = resultViewModel.Customers.Count;
}
httpresponsemessageresponse=client.GetAsync(“api/customer?input=test&$top=2&$skip=0”)。结果;//测试字符串
if(响应。IsSuccessStatusCode){
CustomerSearchResultViewModel resultViewModel=new CustomerSearchResultViewModel();
resultViewModel.Customers=response.Content.ReadAsAsync().Result.ToList();
resultViewModel.TotalResults=resultViewModel.Customers.Count;
}
在本例中,TotalResults的上限为2,而不是返回分页前找到的匹配项的总数

有没有办法通过利用OData获得总体结果?如果这是不可能的,我如何在获取所需号码的同时最好地保留OData功能?

您可以使用OData选项。请求看起来像,
api/customer?input=test&$top=2&$skip=0&$inlinecount=allpages

现在,我们不支持使用默认json和xml格式化程序即时发送count值。您的客户端代码是我们决定默认不发送它的最佳示例。原因是客户不知道如何处理额外的count属性。我们的OData格式化程序默认支持$inlinecount选项,因为OData格式对响应中的计数值的位置有明确的规则

也就是说,您可以做一个简单的更改来支持响应中的count。不过,您的客户端代码也必须更改。有关详细信息,请参阅此项。

您可以使用OData选项。请求看起来像,
api/customer?input=test&$top=2&$skip=0&$inlinecount=allpages

现在,我们不支持使用默认json和xml格式化程序即时发送count值。您的客户端代码是我们决定默认不发送它的最佳示例。原因是客户不知道如何处理额外的count属性。我们的OData格式化程序默认支持$inlinecount选项,因为OData格式对响应中的计数值的位置有明确的规则

也就是说,您可以做一个简单的更改来支持响应中的count。不过,您的客户端代码也必须更改。有关详细信息,请参阅此