I have written an hql to support paging
string hql = @"select distinct mr
from MediaResource as mr
where mr.Deleted= false
and mr.Type = :typeId";
SimpleQuery<MediaResource> q = new SimpleQuery<MediaResource>(hql);
q.SetParameter("typeId", typeId);
q.SetQueryRange(page * pageSize, pageSize);
return q.Execute().ToList();
And then I wrote a test to run this function and get the nhibernate log as
select
*
from
( select
distinct mediaresou0_.MediaResourceID as MediaRes1_7_,
from
MediaResource mediaresou0_
where
mediaresou0_.Deleted=0
and mediaresou0_.Type=:p0 )
where
rownum <=:p1;
:p0 = 1, :p1 = 10
What concerns me is the select * from (select ...) part. Would this be a performance problem? Is it possible to tell Nhibernate to generate sql statement to have only one query?