nhibernate-core icon indicating copy to clipboard operation
nhibernate-core copied to clipboard

NH-2477 - Count after Take return incorect value

Open nhibernate-bot opened this issue 8 years ago • 2 comments

rosieks created an issue:

The following query

issues.Take(30).Count()

return value greater than 30. It should return at most 30.


Fabio Maulo added a comment — :

Test available in the trunk


Ricardo Peres added a comment — :

Confirmed with NH 4.0

nhibernate-bot avatar Oct 12 '17 22:10 nhibernate-bot

I'm trying to resolve this issue, but I think NHibernate generate a correct query (postgres):

select cast(count(*) as int4) as col_0_0_ from Entity entity0_ limit :p0

To work the query should be:

select cast(count(*) as int4) as col_0_0_ from Entity entity0_ where id in (select id from Entity limit 3); 

or

select cast(count(*) as int4) as col_0_0_ from ( select Id from Entity limit :p0 ) entity0_ 

or we can use this code:

var actual = var actual = session.Query<Entity>().Take(3).AsEnumerable().Count();

lillo42 avatar Dec 22 '18 12:12 lillo42

Related to, indeed nearly duplicated by #1342.

fredericDelaporte avatar Dec 22 '18 14:12 fredericDelaporte