1

I have a WebAPI OData controller that I need to do some operation after query applied and before data is returned. In the EnableQuery I can not an extension method to do that.

Indeed I need to remove some record before data is returned to client. This operation can not be done via URI/Query/Filter.

Update

see following code. actual filter is applied on the return value of first ApplyQuery If I do my filter inside it, uri filter is ignore.

Code that I tried to see if an extensions exists:

    public class EQueryAttribute : EnableQueryAttribute
{
    public override IQueryable ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions)
    {
            var retval = base.ApplyQuery(queryable, queryOptions);

        if (queryable.ElementType.Name == "ProductInfoDto")
        {
            var q = retval as IQueryable<ProductInfoDto>;
            return new List<ProductInfoDto>() { new ProductInfoDto { PasName = "123" } }.AsQueryable();
        }

        return retval;

    }

    public override object ApplyQuery(object entity, ODataQueryOptions queryOptions)
    {
        return base.ApplyQuery(entity, queryOptions);
    }

    public override Task OnActionExecutedAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)
    {

        return base.OnActionExecutedAsync(actionExecutedContext, cancellationToken);
    }
}
Afshar Mohebi
  • 10,479
  • 17
  • 82
  • 126

0 Answers0