2013/1/14 NHJunior <[email protected]>:
>>>> In fact, you
>>>> should get the exception already when bigNumber is greater than 0,
>>>>since the SQL with the count will only generate one row.
> Now I get exception only if bigNumber large enough that result collection
> contains 0 items. I think that Count() simply must return 0 in this
> situation.

I took the query you posted:
    currentSession.Query<T>().Skip(bigNumber).Count()

and ran it in in the NHibernate test suite as the equivalent of the
following. I got the same exception.
        currentSession.Query<Order>().Skip(1).Count()

The SQL that is generated wrongly applies the SQL COUNT first, which
is an aggregate so it generates at most one output row. Then skip is
applied so we loose that row too. Which is unexpected by other parts
of the code, hence the exception. I've tested with MS SQL. Maybe a
different SQL dialect or if group by is present, it might cause
different result.

In either case, this is clearly a bug in NHibernate.


>
>>>>On the other hand, this seems like a rather unusual query - why do you
>>>> need it?
> For application service with paging (
> Skip(pageSize*pageNumber).Take(pageSize) ).
> If pageSize big and result page contains 0 items call Count() results to
> crash.

Usually with paging the count is applied without the paging to get to
total number of rows to page over. Why do you need to apply the paging
statements to the count itself?

/Oskar

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to