1
我可能会错过简单的东西,但基于这个博客文章:http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options这应该是工作。我有以下的控制器方法:ODataQueryOptions没有被应用
public virtual IQueryable<DtoAgent> Get(ODataQueryOptions<Agent> options, bool includeInactive = false, bool includeDeleted = false)
{
IQueryable<Agent> agents = null;
if (includeDeleted && includeInactive)
{
agents = agentRepository.FindAll();
}
else if (includeDeleted)
{
agents = agentRepository.FindBy(a => a.ussiStatus == "A");
}
else if (includeInactive)
{
agents = agentRepository.FindBy(a => !a.IsDeleted);
}
if (agents == null)
{
agents = agentRepository.FindByExp(a => a.ussiStatus == "A" && !a.IsDeleted);
}
options.ApplyTo(agents);
return agents.ToDtos<DtoAgent>();
}
当我这样称呼它../api/Agent?$top=10它返回所有的结果不只是10.我可以看到TopQueryOption在选项变量,但它确实似乎没有得到应用。如果我使用[Queryable]属性,但在数据库调用之后应用顶部,这是我试图避免的情况,它可以工作。我在全球一级调用EnableQuerySupport并安装了Nuget包和2012.2更新。谢谢你的帮助。
我很怀疑,非常感谢Youssef! –