Expression Tree Format for OData Queries

Topics: ASP.NET Web API
Jul 9, 2012 at 8:00 PM

When can I find a specification of the existing (RC) and upcoming LINQ expression tree format for OData queries?  I will be writing an IQueryProvider implementation that doesn't talk to a SQL instance and will need to understand the expression tree to perform an OData operator mapping.

Currently, I'm trying to intercept the constructed expression tree in a request to an IQueryable action, but am not having any luck; I can't seem to intercept an action call with the "MS_QueryKey" property set within the request.  What is the recommended way to do this in the current RC release?

Jul 9, 2012 at 8:37 PM
SteveGuidi wrote:

Currently, I'm trying to intercept the constructed expression tree in a request to an IQueryable action, but am not having any luck; I can't seem to intercept an action call with the "MS_QueryKey" property set within the request.  What is the recommended way to do this in the current RC release?

On a side note, I was able to obtain the linq expression tree by returning a custom IQueryable implementation and setting a breakpoint on IQueryable.IQueryProvider<T>.CreateQuery().

Jul 9, 2012 at 9:31 PM

With the RC bits, you can subclass QueryableAttribute and override OnActionExecuted to get hold of the Queryable Expression. For example,

public class MyQueryableAttribute : QueryableAttribute
    {
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            base.OnActionExecuted(actionExecutedContext);

            IQueryable query;
            if (response != null && response.TryGetContentValue(out query))
            {
                var expression = query.Expression;
                
                // evaluate expression and set the result
                ((ObjectContent)response.Content).Value = Evaluate(expression);
            }
        }
    }
 

Jul 11, 2012 at 10:56 AM

For the client side, I am working on a project here:

https://github.com/PocoHttp/PocoHttp

Let me know what you think.