これが私の問題です。ASP.NET Web API 2.0 と QueryableAttribute を使用して、OData フィルタリング機能の一部を利用しています。
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
。