Q: Intercept and override where clause of linq I am in a situation where I cannot add new params to a method, and cannot change the logic of DataQuery either - so I can only change the content of the methods with a similar construction as this, and the properties of T.
IEnumerable<T> Get<T>(DataQuery<T> query) {
  var collection = repo;
  return query.Apply(repo).ToList();
}

My problem is that I want to add support for retrieving Ts assigned to my team, or my company or just me, but I do not have access to any context of "me" from the calling point - they are available on UserContext in the methods.
The DataQuery<T>.Apply() allows me to query on Ts properties like T.caseId <= 4 and will return a list with cases 1-4. which are translated into source.Where(t => t.caseId <= 4)
My idea is to add the following fields to T
bool IsMineQuery
bool IsMyTeamQuery
bool IsMyCompanyQuery

and then intercept the calls to .Where(t => t.IsMineQuery == true) or .Where(t => t.IsMyTeamQuery == true) and rewrite them to .Where(t => t.UserId == UserContext.UserId) or .Where(t => UserContext.TeamIds.Contains(t.TeamId)) but I have no idea of how to intercept the calls.
How do I achieve this?

A: So after fidling around all night I had a break through.
I had to make a custom query provider - I used this tutorial: https://msdn.microsoft.com/en-us/library/bb546158.aspx
then my controllers are of the form
IEnumerable<T> Get<T>(DataQuery<T> query) {
  var collection = new MyQueryable(repo, UserContext);
  return query.Apply(repo).ToList();
}

Then I have changed the tutorial's "InnerMostWhereFinder" to identify if my query has gotten a IsMineQuery or IsMyTeamQuery and replace it with UserContext.TeamIds.Contain(x => x.Team.Id)
Works like a charm, but was not an straight forward solution.
