使用$ expand时,web api页面结果失败

时间:2014-10-07 15:39:00

标签: odata asp.net-web-api2

要从webapi2控制器获取odata样式的内联计数,我在此页面上阅读: http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options我应该从我的方法返回一个PagedResult。我在我的apicontroller中制作了我的方法:

public PageResult<Software> Get(ODataQueryOptions<Software> options)
    {

        ODataQuerySettings settings = new ODataQuerySettings()
        {

        };

        IQueryable results = options.ApplyTo(db.Software, settings);

        return new PageResult<Software>(
            results as IEnumerable<Software>,
            Request.ODataProperties().NextLink,
            Request.ODataProperties().TotalCount
            );
    }

这适用于这样的请求:

http://dummy.com/api/Softwareapi $ inlinecount =所有页&安培; $滤波器=删除%20当量%20false&安培; $的OrderBy = SequenceNo&安培; $顶部= 7和; $跳过= 0

但对于这样的请求:

http://dummy.com/api/Softwareapi $ inlinecount =所有页&安培; $滤波器=已删除%20当量%20false&安培; $的OrderBy = SequenceNo&安培; $顶部= 7&安培; $跳过= 0&安培;的 $扩大=供应商 < / p>

我明白了:

    <Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>Value cannot be null. Parameter name: data</ExceptionMessage>
<ExceptionType>System.ArgumentNullException</ExceptionType>
<StackTrace>
at System.Web.Http.OData.PageResult`1..ctor(IEnumerable`1 items, Uri nextPageLink, Nullable`1 count) at DigiCampuz.Controllers.SoftwareApiController.Get(ODataQueryOptions`1 options) in c:\Users\bzs\Documents\Visual Studio 2012\Projects\DigiCampuz Webapp\DigiCampuz\Controllers\SoftwareApiController.cs:line 41 at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 

如果我在vs调试器中使用快速监视功能,我可以看到结果具有正确数量的项目,而这些项目有供应商,但我似乎无法获得pagedresult来查看。

这里有人想帮我这个吗?

0 个答案:

没有答案