-
Notifications
You must be signed in to change notification settings - Fork 932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NH-3851 - using Skip(aNumber).Count() where aNumber is greater than total count of records results in ArgumentOutOfRangeException #1342
Comments
This is SQLite and SQL Server 2012 (and some others?) behaviour: select count(*) from A limit 100 offset 100; Would be executed like: select * from (select count(*) from A) limit 100 offset 100; instead of expected: select count(*) from (select * from A limit 100 offset 100); |
It does not throw the exception anymore, but returns invalid results (always 0), which is even worse. |
I do not think that the mentioned "expected" query is really what should be expected from the mentioned starting SQL. That is a matter of knowing what is the priority of the By example the PostgreSQL documentation states:
Which I can only interpret as them being applied last. Same for SQLite:
(SQL-Server documentation is quite lame in its current state on docs: The trouble lies in the Linq translation in my opinion. It should not swap the |
Subqueries in the from clause are not supported in HQL, unfortunately. And this is the HUGE change in the parser. |
Then it should either throw a "not supported exception" or swap to in-memory evaluation of the aggregation done on the paginated results. |
Reducing the priority to minor: the opener use case is not efficient and common. Counting the number of results actually present on a page is better done in memory in most cases, since usually the page data is loaded or about to be loaded. Or else the global number of results can be counted (so without paging), and the actual number of elements expected for a given page can then be computed in memory. |
We encountered the same Exception using Any(): The query: The stack: The protected virtual object ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery) method in DefaultQueryProvider.cs assumes the call to query.List() will return one or more results; if it returns nothing then the call to results[0] throws the ArgumentOutOfRangeException. I rewrote the query to use RowCount() to resolve the issue. |
Can confirm it just returns the wrong amount, as described in #1081. Any ideas for workarounds or how to solve this? |
fredericDelaporte wrote
hazzik wrote
So at least now it's fixable as subquery support is already implemented in #2551 |
John Thornborrow created an issue — 26th February 2016, 21:59:14:
Ricardo Peres added a comment — 27th February 2016, 11:01:10:
John Thornborrow added a comment — 24th March 2016, 22:25:50:
The text was updated successfully, but these errors were encountered: