When using $filter alone a result is returned, when using both $filter and $select no results are returned
====== Update: See comments below, root cause is that OData.WebApi is putting a SelectExpandBinder into the expression tree and I need a way to disable this so it applies a simple anonymous type projection as expected. SelectExpandBinder is a class that is internal to OData.WebApi and there should be no expectation that downstream IQueryable implementations will understand how to interpret it. ======
This query returns an entity successfully: http://localhost/Example/Collection?$filter=someProperty eq 'someValue'
When adding a $select option as well, no results are returned: http://localhost/Example/Collection?$filter=someProperty eq 'someValue'&$select=anotherProperty
In this example, someProperty is not the key or I would have used (which does also work): http://localhost/Example/Collection('someValue')?select=anotherProperty
My get implementation:
[EnableQuery(
EnableConstantParameterization = false,
EnsureStableOrdering = false,
AllowedQueryOptions = (AllowedQueryOptions)(AllowedQueryOptions.Supported - AllowedQueryOptions.Skip - AllowedQueryOptions.Count))]
public async Task<IQueryable<EntityDto>> Get()
{
// lots of stuff here that isn't relevant
IQueryable<EntityDto> queryable = await MyDatabase.Collection.GetQueryable();
return queryable;
}
Assemblies affected
System.Web.OData v4.0.30319
Reproduce steps
This is quite straightforward, see description.
Expected result
Filter is working, adding select on top of it should return the selected sub-set of properties from the entities selected by the filter.
Actual result
When adding a select to the (working) filter, no results are returned.
Additional details
I can provide a full zip of the project via internal email to help repro this in case you suspect it is something in the IQueryable implementation, however the IQueryable comes from the DocumentDB client and applying the same Linq .Where() and .Select() to it does return the expected results, so something isn't roundtripping here even when I load the appropriate URI with the $filter and $select manually.
Update: This appears to be an incompatibility between the DocumentDB client IQueryable implementation and how OData is applying the query URL to the IQueryable. I'm not sure if this is a bug in OData or DocumentDB but I was able to confirm it against a (small) test DB by returning docDbQueryable.ToArray().AsQueryable() and that caused it to start working. Obviously this is not a workable solution.
I managed to root cause the incompatibility. Just like I had to set "EnableConstantParameterization = false" to disable OData.WebApi from wrapping constants in System.Web.OData.Query.Expressions.LinqParameterContainer (making a non-standard expression tree), I need an option to disable wrapping projections in System.Web.OData.Query.Expressions.SelectExpandBinder but simply apply them directly to the IQueryable. The IQueryable implementation I am using (from DocumentDB) quite understandably has absolutely no idea what that type is or how to evaluate or instantiate it. It should be applying a projection of an anonymous type.
@nickkin-msft Thanks your input and please feel free to re-open it or file a new issue for us if you have further concerns.
Not sure how to re-open but this is still a big issue for us. We end up creating custom odata functions just to do projection for our users since projection against a DocDB IQueryable doesn't work. The cause is SelectExpandBinder classes spread throughout the projection portion of the query tree, resulting in a very "weird" expression. An option to just do a "normal" projection would be very helpful for anyone targeting an IQueryable implementation that (very reasonably) doesn't understand how to deal with that.