2016-09-12 5 views
0

リストに拡大$でオプションをODataのApplyQueryメソッドの結果を変換します私はODataの入手方法持って<T>

public class ProductController : ApiController 
{ 
    [MyEnableQuery(PageSize = 48, AllowedQueryOptions = AllowedQueryOptions.OrderBy | AllowedQueryOptions.Top | AllowedQueryOptions.Skip | AllowedQueryOptions.InlineCount | AllowedQueryOptions.Filter | AllowedQueryOptions.Expand | AllowedQueryOptions.Select, AllowedFunctions = AllowedFunctions.SubstringOf | AllowedFunctions.ToLower)] 
    public IQueryable<tbDefine_Products> GetProducts(ODataQueryOptions opts,[FromODataUri] int CategoryID) 
    { 
     ProductHandler _handler = new ProductHandler(); 
     IQueryable<tbDefine_Products> _list =_handler.GetProductActiveList(CategoryID); 
     return _list; 
    } 
} 

を、私は照会するApplyQueryメソッドをオーバーライドしている:

public override IQueryable ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions) 
    { 
     IQueryable<Object> _list = base.ApplyQuery(queryable, queryOptions).Cast<Object>(); 
     return _list; 
    } 

を私はフォームを使用しています拡張オプションを使用したODateクエリのオプション:

http://localhost:5125/api2/product?CategoryID=-1&$skip=9&$top=1&$expand=tbDefine_Category 

私は、私のApplyQueryメソッドでbas e.ApplyQuery結果i 'は型のオブジェクトをキャストすること

できません。次のエラーを取得するリストのいくつかのフォームにして、いくつかの修正のためにそれを反復しかし、私はどのように知らない...

/* IQueryable<MyExpandedType> _list = base.ApplyQuery(queryable, queryOptions).Cast<MyExpandedType>(); 
       List<MyExpandedType> _list2 = _list.ToList<MyExpandedType>(); 
       for (int i = 0; i < _list2.Count; i++) 
       { 
         some modification here 
       } */ 

SelectAllAndExpand`1 [EDMX.tbDefine_Products] 'に「EDMX.tbDefine_Products」と入力します。

答えて

0

あなたがapplyqueryメソッドの署名を修正する必要があると思います。それはIqueryableを返すので、署名は私が推測するものと同じでなければなりません。

public override IQueryable ApplyQuery。

関連する問題