使用Web Api 2的$ select语句出现意外结果

时间:2013-11-08 16:19:19

标签: asp.net-mvc asp.net-web-api odata

我正在使用MVC 4和WebApi 1开发一个项目,它运行良好, 在将其升级到MVC 5和WebApi 2后,一切都很好,除了这种情况:当我在查询中使用$ select语句并指定一些属性时,options.ApplyTo()方法返回意外结果:

System.Web.Http.OData.Query.TruncatedCollection`1[System.Web.Http.OData.Query.Expressions.SelectExpandBinder+SelectSome`1[MvcApp.Domain.Entities.Users]]

为什么会发生这种变化,以及如何将其转换为IQueryable<用户和GT;作为WebApi 1? 我的代码在这里:

public PageResult<Users> Get(ODataQueryOptions options)
{
    ODataQuerySettings settings = new ODataQuerySettings() { PageSize = 10 };
    IQueryable results = options.ApplyTo(Repository.Data, settings);
    var items = results as IEnumarable<Users>;
    // items will be null if you $select some properties!
    return new PageResult<Users>(items, null, Request.GetInlineCount().Value);
}

请帮助。

0 个答案:

没有答案