Short answer: Look for the CastResultOperator in the ResultOperators
collection of the SubQueryExpression's QueryModel. Detect that the
inner QueryModel is trivial by inspecting
QueryModel.IsIdentityQuery(), then use the inner QueryModel's
FromExpression. Do this in your back-end’s respective
VisitSubQueryExpression visitor method, or use the
SubQueryFromClauseFlattener.
Long answer: This became a blog-post. Read it here:
<https://www.re-motion.org/blogs/mix/archive/2010/09/23/re-linq-dealing-with-sub-queries-in-a-from-clause.aspx>.
Hope this helps,
Fabian
Well, I think you can handle both cases the same way:
Q1: (from o in session.Query<Dog>() select o).Cast<Animal>()
=> You get a QueryModel that has a CastResultOperator.
Q2: from Dog o in session.Query<Dog>() select o
is just a shortcut for:
Q2a: from o in session.Query<Dog>().Cast<Dog>() select o
which is represented by re-linq the same way as:
Q2b: from o in (from x in session.Query<Dog>() select x).Cast<Dog>() select o
So, the inner SubQueryExpression's QueryModel is exactly the same as
in Q1 above. You should be able to handle it the same way, too.
(The rest is only elimination of the sub-query. But the handling of
the QueryModel with the Cast should be very similar.)
Fabian