Upon further review of the code, there is actually a good reason why the Query object is not modifiable in the Fetching event on the client-side. The reason is that the original query you submitted on the client may not be the same query you get in the Fetching event, because the query in the latter may be a "reduced" version of the query.
Say for example your original query was "Get me all the Customers who reside in the USA". And let's say there are a total of 100 customers that satisfy the query. If there are 20 customers already residing in the cache, then the query in the Fetching event will be reduced to fetch just the remaining 80 customers. In this case, the original query is not the same as the query in the Fetching event, and modifying this query would be a bad idea.
In our upcoming release (v5.1.1), we will provide a new event for modifying the query: EntityManager.Querying. The Querying event will fire before the EntityManager queries data from an EntityServer. Note that cache-only queries or optimized queries that are handled by the client will not go thru this handler.
Here's an example of how it might be used:
public void QueryModifyQuery() {
_em1.Querying += (s, e) => {
var query = e.Query as EntityQuery;
if (query != null) {
var newQuery = query.Filter((IQueryable<Customer> q) => q.Where(c => c.Country == "USA"));
e.Query = newQuery;
}
};
var custs = _em1.Customers.Take(7).ToList();
Assert.IsTrue(custs.All(c => c.Country == "USA"));
}