When using an order by, conditional projection and SetFirstResult() together in a query I get this error:
Invalid index 4 for this SqlParameterCollection with Count=4
In my experience, this error usually happens when you have one field mapped to two properties, as outlined here. But it is not the case in this situation, the query works fine until, I pass a value greater than 0 to SetFirstResult().
This bug logged with Nhiberbate seems very simular, but it was fixed 2 years ago.
Any suggestions on how to proceed? Here is a sample of the code:
var query = Session.CreateCriteria<KeepItem>(KeepAlias)
.CreateAlias("Resource", ResourceAlias)
.CreateAlias("Memory", MemoryAlias, JoinType.LeftOuterJoin);
// other code
query.AddOrder
(
Order.Asc
(
Projections.Conditional
(
Restrictions.IsNull(MemoryAlias + ".MinDate"),
Projections.Conditional
(
Restrictions.IsNull(ResourceAlias + ".MinDate"),
Projections.Constant(DateTime.MaxValue),
Projections.Property(ResourceAlias + ".MinDate")
),
Projections.Property(MemoryAlias + ".MinDate")
)
)
);
//other code
query.SetFirstResult(skip);
query.SetMaxResults(take);
return query.List<KeepItem>();