I'm using the following c# code:
public IList<T> GetAllByExpression(Expression<Func<T, bool>> expression, int startIndex, int count, Func<T, DateTime> dateTimeSelector)
{
using (ISession session = NHibernateHelper.GetSession())
{
return session.Query<T>()
.Where(expression)
.OrderBy(dateTimeSelector)
.Skip(startIndex - 1)
.Take(count)
.ToList();
}
}
update: even the follwoing code throws the same exception:
public IList<T> GetAllByExpression(Expression<Func<T, bool>> expression, int startIndex, int count, Expression<Func<T, DateTime>> dateTimeSelector)
{
using (ISession session = NHibernateHelper.GetSession())
{
return session.Query<T>()
.Where(expression)
//.OrderBy(dateTimeSelector)
//.Skip(startIndex - 1)
//.Take(count)
.ToList();
}
}
And get Nh error:
Unable to cast object of type 'NHibernate.Hql.Ast.HqlCast' to type 'NHibernate.Hql.Ast.HqlBooleanExpression'.
what am I doing wrong?
The problem was that I wrote short condition in the expression: as ((a == null)? true : a > b) NH casting fails on that (?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With