我有以下代码段,其中我收到错误
using (var session = Database.OpenSession())
{
var q = from x in session.Query<User>()
where x.UserName == username & x.Password==EncodePassword(password)
select x;
if (q.Count() > 0)
{
result = true;
}
}
在if语句中我收到错误
Unable to cast object of type 'NHibernate.Hql.Ast.HqlBitwiseAnd' to type 'NHibernate.Hql.Ast.HqlBooleanExpression'.
答案 0 :(得分:7)
怎么样:
using (var session = Database.OpenSession())
{
var q = from x in session.Query<User>()
where x.UserName == username && x.Password==EncodePassword(password)
select x;
if (q.Count() > 0)
{
result = true;
}
}
检查查询中的双&符号,直接在where
部分。