Cast

18 views
Skip to first unread message

Fabio Maulo

unread,
Sep 22, 2010, 5:04:32 PM9/22/10
to re-motion Users
for this query
from Dog o in session.Query<Dog>() select o

I would catch the Cast method but it is parsed as SubQueryExpression.

Have you any advise ?
Thanks.

Fabian Schmied

unread,
Sep 23, 2010, 3:45:48 AM9/23/10
to re-moti...@googlegroups.com

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

Fabio Maulo

unread,
Sep 23, 2010, 7:11:04 AM9/23/10
to re-motion Users
Thanks for the large explication in the blog-post.
I can't understand why I can manage this: (from o in
session.Query<Dog>() select o).Cast<Animal>()
but not the original case in the same way....

btw, no problem I think that I have understood the root problem.
Thanks for your support.
> <https://www.re-motion.org/blogs/mix/archive/2010/09/23/re-linq-dealin...>.
>
> Hope this helps,
> Fabian

Fabian Schmied

unread,
Sep 23, 2010, 9:23:22 AM9/23/10
to re-moti...@googlegroups.com
> Thanks for the large explication in the blog-post.
> I can't understand why I can manage this: (from o in
> session.Query<Dog>() select o).Cast<Animal>()
> but not the original case in the same way....

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

Reply all
Reply to author
Forward
0 new messages