Odata 使用$expand时webapi pagedresult失败

Odata 使用$expand时webapi pagedresult失败,odata,asp.net-web-api2,Odata,Asp.net Web Api2,要从webapi2控制器获取odata样式的内联计数,我在本页读到: 我应该从我的方法返回PagedResult。我在apicontroller中创建的方法如下: public PageResult<Software> Get(ODataQueryOptions<Software> options) { ODataQuerySettings settings = new ODataQuerySettings() {

要从webapi2控制器获取odata样式的内联计数,我在本页读到: 我应该从我的方法返回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
            );
    }
公共页面结果获取(ODataQueryOptions选项)
{
ODataQuerySettings设置=新的ODataQuerySettings()
{
};
IQueryable results=options.ApplyTo(db.Software,settings);
返回新页面结果(
结果是不可数的,
Request.ODataProperties().NextLink,
Request.ODataProperties().TotalCount
);
}
对于这样的请求,这很好:

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
            );
    }
?$inlinecount=allpages&$filter=Deleted%20eq%20false&$orderby=SEQUENCE否&$top=7&$skip=0

但是对于这样的请求:

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
            );
    }
?$inlinecount=allpages&$filter=Deleted%20eq%20false&$orderby=SequenceNo&$top=7&$skip=0&$expand=Supplier

我得到:

    <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 

发生了一个错误。
值不能为null。参数名称:数据
System.ArgumentNullException
在c:\Users\bzs\Documents\visualstudio 2012\Projects\DigiCampuz Webapp\DigiCampuz\Controllers\SoftwareApiController.Get(ODataQueryOptions`1 options)中的System.Web.Http.OData.PageResult`1..ctor(IEnumerable`1项,Uri nextPageLink,null`1计数)中的DigiCampuz.Controllers.SoftwareApiController.Get(ODataQueryOptions`1选项)中在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.c_uDisplayClass10.b_u9(对象实例,对象[]方法参数)中的System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(对象实例,对象[]参数)在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext,IDictionary`2参数,CancellationToken CancellationToken)----从引发异常的前一个位置开始的堆栈结束跟踪--在System.Runtime.CompilerServices.TaskWaiter.ThrowForOnSuccess(Task任务)在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务
如果我在vs调试器中使用quick watch功能,我可以看到结果中有正确数量的项目,并且这些项目有供应商,但我似乎无法让pagedresult看到这一点


这里有人想帮我吗?

这是一个我如何让“扩展”工作的例子。让我知道它是否适合你。最后我只需切换到基于odatav4的完整控制器,没有问题和更多选项。