我在 ASP.NET Web API 应用程序中使用开箱即用的 ValuesController
public class ValuesController : ApiController
{
// GET api/values
[Queryable(PageSize = 1)]
public IQueryable<string> Get()
{
return new string[] { "value1", "value2", "value3", "value4", "value5" }.AsQueryable();
}
}
当我get http://localhost/api/values?$inlinecount=allpages
这是回应
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>value1</string>
</ArrayOfString>
我已取消注释config.EnableQuerySupport();
过滤,排序工作正常。
如果我尝试get http://localhost/api/values?$inlinecount=XXXXX
出现异常,那么 Web API 应用程序似乎知道inlinecount
<Message>The query specified in the URI is not valid.</Message>
<ExceptionMessage>'xxx' is not a valid value for $inlinecount.</ExceptionMessage>
<ExceptionType>Microsoft.Data.OData.ODataException</ExceptionType>
我肯定有 Microsoft.AspNet.WebApi.OData 包 - 这是包管理器控制台的输出
PM> Install-Package Microsoft.AspNet.WebApi.OData
Attempting to resolve dependency 'Microsoft.Net.Http (= 2.0.20710.0 && < 2.1)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Client (= 4.0.20710.0 && < 4.1)'.
Attempting to resolve dependency 'Newtonsoft.Json (= 4.5.6)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Core (= 4.0.20710.0 && < 4.1)'.
Attempting to resolve dependency 'Microsoft.Data.OData (= 5.2.0 && < 5.3.0)'.
Attempting to resolve dependency 'System.Spatial (= 5.2.0)'.
Attempting to resolve dependency 'Microsoft.Data.Edm (= 5.2.0)'.
'Microsoft.AspNet.WebApi.OData 4.0.0' already installed.
WebServicesProject already has a reference to 'Microsoft.AspNet.WebApi.OData 4.0.0'.
有什么建议么?