我用下面的C#代碼的對象:無法投型「NHibernate.Hql.Ast.HqlCast爲鍵入「NHibernate.Hql.Ast.HqlBooleanExpression
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();
}
}
更新: 連在follwoing代碼拋出同樣的異常:
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();
}
}
並獲得新罕布什爾錯誤:
Unable to cast object of type 'NHibernate.Hql.Ast.HqlCast' to type 'NHibernate.Hql.Ast.HqlBooleanExpression'.
我做錯了什麼?
可能是它的您提供的表達到哪裏失敗 – Baz1nga