次のシナリオがあります: 次のような ODataQueryOptions を受け入れる "GetAll" メソッドを持つ ProductsController:
[GET("Products", RouteName = "GetAllProducts")]
public ProductDTO[] Get(ODataQueryOptions options)
{
//parse the options and do whatever...
return new ProductDTO[] { };
}
次のような GetProducts メソッドを持つ CategoryController:
[GET("Category/{id}/Products", RouteName = "GetProductsByCategory")]
public HttpResponseMessage GetProducts(int id, ODataQueryOptions options)
{
//Request URL can be "api/Category/12/Products?$select=Name,Price&$top=10"
//Need to do a redirect the ProductsController "GetAllProducts" action
HttpResponseMessage msg = new HttpResponseMessage(HttpStatusCode.RedirectMethod);
msg.Headers.Location = new Uri(Url.Link("GetAllProducts",options));
// how do we send the odata query string"$select=Name,Price&$top=10"
//to the ProductsController? passing "options" directly does not work!
return msg;
}
CategoryController の特定のカテゴリで製品をフェッチするロジックを再定義したくありません。する方法はありますか
1) リダイレクトの一部として ODataQueryOptions を渡しますか?
2) オプションを変更して、フィルター条件を追加できますか? 上記の例では、「GetAllProducts」が次のリクエストを受け取るように、リダイレクトを行う前に現在の CategoryID に追加のフィルター条件を追加したいと思います:「api/Products?$select=Name,Price&$top=10& $ 」フィルター=CategoryID eq 12 "
上記は理にかなっていますか、それとも別の方法でアプローチする必要がありますか?
前もって感謝します。