I've got a simple query between two dates on a table Performance
Code:
IQuery query = m_session.CreateQuery("from Performance p " +
"where p.PerformanceDate >= :fromDate " +
"and p.PerformanceDate <= :toDate ")
.SetDateTime("fromDate", (DateTime)fromDate)
.SetDateTime("toDate", (DateTime)toDate);
That creates the following SQL query
Code:
select performanc0_.Id as Id25_, performanc0_.CreatedDate as CreatedD2_25_,
performanc0_.CreatedId as CreatedId25_,
performanc0_.ModifiedDate as Modified4_25_, performanc0_.ModifiedId as ModifiedId25_,
performanc0_.Deleted as Deleted25_, performanc0_.PerformanceDate as Performa7_25_,
performanc0_.VenueId as VenueId25_, performanc0_.CountryId as CountryId25_,
performanc0_.Provisional as Provisi10_25_, performanc0_.Premiere as Premiere25_,
performanc0_.ProductionPremiere as Product12_25_, performanc0_.AgencyId as AgencyId25_,
performanc0_.Details as Details25_, performanc0_.WorkId as WorkId25_
from Performance performanc0_ where ( (performanc0_.deleted is null or performanc0_.deleted = 0))
and ((performanc0_.PerformanceDate>=@p0 )and(performanc0_.PerformanceDate<=@p1 ));
@p0 = '06/05/2009 00:00:00', @p1 = '18/05/2009 00:00:00'
Which works fine and returns the data I expect.
But if I add a SetMaxResults to the HQL
Code:
IQuery query = m_session.CreateQuery("from Performance p " +
"where p.PerformanceDate >= :fromDate " +
"and p.PerformanceDate <= :toDate ")
.SetDateTime("fromDate", (DateTime)fromDate)
.SetDateTime("toDate", (DateTime)toDate)
.SetMaxResults(100);
The SQL produced is not correct - the last parameter is used for all parameters in the query string - in this instance @p1
Code:
SELECT TOP 100 Id25_, CreatedD2_25_, CreatedId25_, Modified4_25_, ModifiedId25_, Deleted25_,
Performa7_25_, VenueId25_, CountryId25_, Provisi10_25_, Premiere25_, Product12_25_, AgencyId25_,
Details25_, WorkId25_
FROM (select performanc0_.Id as Id25_, performanc0_.CreatedDate as CreatedD2_25_,
performanc0_.CreatedId as CreatedId25_, performanc0_.ModifiedDate as Modified4_25_,
performanc0_.ModifiedId as ModifiedId25_, performanc0_.Deleted as Deleted25_,
performanc0_.PerformanceDate as Performa7_25_, performanc0_.VenueId as VenueId25_,
performanc0_.CountryId as CountryId25_, performanc0_.Provisional as Provisi10_25_,
performanc0_.Premiere as Premiere25_, performanc0_.ProductionPremiere as Product12_25_,
performanc0_.AgencyId as AgencyId25_, performanc0_.Details as Details25_,
performanc0_.WorkId as WorkId25_, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP)
as __hibernate_sort_row from Performance performanc0_
where ( (performanc0_.deleted is null or performanc0_.deleted = 0))
and ((performanc0_.PerformanceDate>=@p1 )and(performanc0_.PerformanceDate<=@p1 )))
as query WHERE query.__hibernate_sort_row > 0
ORDER BY query.__hibernate_sort_row; @p0 = '06/05/2009 00:00:00', @p1 = '18/05/2009 00:00:00'
I've extended this to use three parameters and get the same result - the last parameter is put inside the query for all parameters.
Am i using SetMaxResults correctly? Why would adding SetMaxResults cause the result set to change?
Thanks