Hi Gunnar,
How do you define "outer query"?
The QueryModel returned by re-linq is designed to have a similar structure as a C# syntactic sugar LINQ query (the "from ... where ... from ... join ... order by ... select ..." syntax, followed by other query operators modifying the query result). In general, re-linq will introduce subqueries only when it needs to so it can represent the actual query within this model.
As an example, consider an "OrderBy" placed after a "Take" - here, a subquery is required to represent the query as a QueryModel (because "Take" is at the "end" of the query, but "OrderBy" is in the middle). The following three queries are all equivalent (I think), so re-linq cannot differentiate them.
var query1 = inner.Cacheable().Take(10).OrderBy(x => x.Item);
var query2 = from x in inner.Cacheable().Take(10)
order by x.Item
select x;
var query3 = from x in inner.Cacheable().Take(10).OrderBy(x => x.Item)
select x;
re-linq's QueryModel will look like query2, wrapping "inner.Cacheable().Take(10)" into a SubQueryExpression. To me, it's now not clear if "Cacheable()" is part of the "outer query" or not. Regarding query1, it looks like it is. Regarding query2 and query3, it doesn't.
So, depending on your definition of "outer query", just checking whether the result operator is part of the "outermost" QueryModel (i.e., not embedded within a SubQueryExpression) could be enough. If it's not, you need to define what "outer query" means and then you can implement code checking for this condition.
Best regards,
Fabian