Select after Take does not work properly
Description
Environment
Attachments
Activity

Fabio Maulo July 30, 2011 at 2:11 PM
Closed after final release of NH3.2.0GA

Fabio Maulo June 19, 2011 at 7:24 AM
Yes are different cases:
artists.OrderBy(a => a.Age).Take(10).Select(a => a.Id)
artists.Take(10).OrderBy(a => a.Age).Select(a => a.Id)
Are two completely different SQL with different results.

Kelly Stuard June 17, 2011 at 9:28 AM
I grabbed trunk and tried this out. This simple case has been fixed. However, further testing needs to be done to have it be a complete feature.
Sure this works:
artists.Take(10).Select(a => a.Id)
But these don't:
artists.OrderBy(a => a.Age).Take(10).Select(a => a.Id)
artists.Where(a => a.Age > 21).Take(10).Select(a => a.Id)
It fails with the original error. (PolymorphicQuerySourceDetector)
If this needs to have additional test cases or be another bug, please let me know; I'm still new around here. I'll be happy to do either/both.

Fabio Maulo May 23, 2011 at 11:44 AM
The matter is not when the last sentence is just a select...
in that case it can be reduced.
In practice this HQL
select a.id from Artist a where a in (from Artist take 3)
can be reduce to this other
select a.id from Artist a take 3
The matter is when the clause after a skip/take has a body (re-linq meaning of it) as
Query<A>().Take(10).Where(x=> x.Name.StartWith("P"))
In this last case we have to transform it with a subquery (... where possible in HQL)

Stefan Wenig May 23, 2011 at 8:39 AM
I can't see a situation with a semantic difference between take + select and select + take. If the two queries that Fabio provided don't return the same results, I'd question the accuracy of at least one of them. So I'd say swithing consecutive Take and Select calls is OK.
But why would you want to do this? As soon as anything gets between Take and Select, you'll have to go the other path anyway. If you have a good way to specify it "right" in HQL, such as the sub query (from Artists take 3), I'd take it.
Details
Details
Assignee
Reporter

artists.Take(10).Select(a => a.Id) throws exception on
NHibernate.Hql.Ast.ANTLR.PolymorphicQuerySourceDetector.GetClassName(IASTNode querySource) en PolymorphicQuerySourceDetector.cs: line 62
artists.Select(a => a.Id).Take(10) works properly
These two queries work with the old provider.