Hi, we are a big user of WCF Data Services and we have a problem with query interceptors. As our API is multi-tenanted we use QueryInterceptor to limit access i.e.
[QueryInterceptor("Customers")]
public Expression<Func<Customer, bool>> OnQueryCustomers()
{
return p => p.TenantID == GetTenantIDForLoggedInUser();
}
[QueryInterceptor("Orders")]
public Expression<Func<Order, bool>> OnQueryOrders()
{
return p => p.TenantID == GetTenantIDForLoggedInUser();
}
There is a one to many relationship between Customer and Order - Customer has Many Orders.
However when you issue a projection query with an $expand statement i.e.
Orders.Take(1).Select(p=> new {p.OrderName,p.Customer.CustomerId, p.Customer.CustomerName})
or
http://localhost/Service.Web.TestApi/TestAPI.svc/Orders()?$top=1&$expand=Customer&$select=OrderName,Customer/CustomerId,Customer/CustomerName
The query crashes with
Could not translate expression ..... into SQL and could not treat it as a local expression.
Either the Expression to be rendered properly or ignore the Query Interceptor if the current entity set is part of an expand statement.
BTW - this is using Linq2SQL but EF doesn't work either. I have tested on WCF Data Services 4,5.0.2,5.1 & 5.2.0-rc1
Any suggestions?
Thanks
Toby