0

OData endpoint is created using ASP.NET Web API 2.0

Trying to create a Query Interceptor in the ODataController like shown in the below code:

public class AVMItemController : ODataController
{
    ADWAppContext sampleADW = new ADWAppContext("Server=XXX;Database=XXX;User ID=XXX;password=xxx;Trusted_Connection=false;Encrypt=true");

    // GET: odata/AVM
    [EnableQuery(PageSize=25)]
    public IQueryable<ADWAppContext.AVMItem> GetAVMItems()
    {
        return sampleADW.AVMItems.AsQueryable<ADWAppContext.AVMItem>();
    }

    [QueryInterceptor("AVMItems")]
    public Expression<Func<ADWAppContext.AVMItem, bool>> FilterAVMItems()
    {
        return avm => avm.avmId > 1000;
    }
}

All the OData queries are processed with out considering the predicate mentioned in Query Interceptor. I have a breakpoint in Query Interceptor Method which never hits.

Srinivas
  • 2,479
  • 8
  • 47
  • 69

1 Answers1

5

Web API OData does not support query interceptors.

lencharest
  • 2,825
  • 2
  • 15
  • 22
  • Not true, according to https://blogs.msdn.microsoft.com/odatateam/2011/01/20/odata-and-oauth-protecting-an-odata-service-using-oauth-2-0/ – Hrvoje Matic Feb 19 '17 at 20:37
  • @HrvojeMatić: That article is out of date. The code is based on the old WCF implementation of OData. Query interceptors are not supported for OData in Web API. – lencharest Mar 16 '17 at 18:16