を行い、その後、エンティティのコレクションで動作し、私は次のコードを持っている:CurrentTestResultController.csでのOData-V4私ODATA-v4のコントローラで機能
var fn = reportModelBuilder.EntityType<CurrentTestResult>()
.Collection.Function("Breakdown").Returns<int>();
を、私は一見シンプルを持っている:
[EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All)]
[HttpGet]
public IHttpActionResult Breakdown()
{
var count = dataService.GetAll()
.Select(x => x.TestResultTypeId)
.Distinct()
.Count();
return Ok(count);
}
本質的に、コレクション内のすべてのエンティティについて、セット内に出現する別のTestResultTypeId
を返します。 (これは些細な操作ですが、私ははるかに複雑だ、本当に人生のシナリオに簡略化)を行うのは簡単だった
を - しかし、私は最初フィルタに見えることはできません、それは上で動作する必要がありCurrentTestResult
のコレクション。
デフォルトですべてのCurrentTestResultエンティティ
localhostの/アプリ/ odatareport/CurrentTestResult/Default.Breakdown
戻り
{
@odata.context: "http://localhost/app/odatareport/$metadata#Edm.Int32",
value: 5
}
(正しい結果上で動作し、この要求は、明確な5がありますタイプ)
しかし、このリクエストは、単に最初にフィルターをかけようとすると失敗します。
localhostの/アプリ/ odatareport/CurrentTestResult/Default.Breakdown?$トップ= 2
戻り
{
error: {
code: "",
message: "The query specified in the URI is not valid. The requested resource is not a collection. Query options $filter, $orderby, $count, $skip, and $top can be applied only on collections.",
innererror: {
message: "The requested resource is not a collection. Query options $filter, $orderby, $count, $skip, and $top can be applied only on collections.",
type: "Microsoft.OData.ODataException",
stacktrace:
" at System.Web.OData.EnableQueryAttribute.ValidateSelectExpandOnly(ODataQueryOptions queryOptions) at System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor, ODataQueryContext queryContext) at System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)"
}
}
}
私の知る限りは、ODATAパイプラインを理解し、なぜこれが失敗した理にかなっています。コントローラメソッドはIQueryableを返し、次にODATA $フィルタ、$ topなどが適用されます。
私は、すでにフィルタリングされているセットを操作する機能が必要です。
私も可能なことをしようとしていますか?
私は内訳方法自体はそれで)(.GetAllを持っていますが、MUT方法前にフィルタリングを適用する方法があることを得る -
それ以外の場合、これはすべての非常に無意味です....
私はコードをステップ実行するとオプションを適用しますが、クライアントにはhttps:// imgurがあります。 com/a/dU32b – Matt
Nevermind、AllQueryOptions属性を削除するのを忘れました - ありがとうございました! – Matt
優秀、問題ありません – Moho