這是我的問題。我正在使用ASP.NET Web API 2.0和QueryableAttribute來利用一些OData過濾功能。使用OData修改ASP.NET Web API返回的響應內容QueryableAttribute
public class VideoController : ApiController
{
[HttpGet]
[Route("activevideos")]
[Queryable]
public IEnumerable<Video> GetActiveVideos(ODataQueryOptions<Video> options)
{
return new GetvContext().Videos.Where(c => c.IsActive);
}
}
現在,我有一個類,我一直在使用修改響應對象和包含的實體。在開始使用QueryableAttribute之前,這工作正常。在此之前,我從前一個方法而不是IEnumerable返回一個List。
public class TestMessageProcessHandler : MessageProcessingHandler
{
protected override HttpResponseMessage ProcessResponse(
HttpResponseMessage response, CancellationToken cancellationToken)
{
var content = ((ObjectContent)(response.Content)).Value;
// Do something here with the content. This used to be a List<Video>
// but now the object it is of type:
// System.Data.Entity.Infrastructure.DbQuery<System.Web.Http.OData.Query.Expressions.SelectExpandBinder.SelectSome<Content.Api.Video>>
}
}
我需要能夠從該得到的實體,我不知道如何從類型得到:
System.Data.Entity.Infrastructure.DbQuery<System.Web.Http.OData.Query.Expressions.SelectExpandBinder.SelectSome<Content.Api.Video>>
喜歡的東西List<Video>
這樣我就可以修改Video
對象。
的未來版本我有OData的完全沒有經驗,所以我可能是完全錯誤的在這裏,但不應該'GetActiveVideos'方法返回'IQueryable