簡単なものが欠けているかもしれませんが、このブログ投稿に基づいています: http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-optionsこれはすべきです働く。次のコントローラーメソッドがあります。
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 だけでなくすべての結果が返されます。options 変数に TopQueryOption が表示されますが、適用されていないようです。[Queryable] 属性を使用すると機能しますが、回避しようとしている DB 呼び出しの後にトップが適用されます。グローバル レベルで EnableQuerySupport を呼び出しており、Nuget パッケージと 2012.2 更新プログラムの両方がインストールされています。ご協力いただきありがとうございます。