无法将类型为'NHibernate.Hql.Ast.HqlBitwiseAnd'的对象强制转换为'NHibernate.Hql.Ast.HqlBooleanExpression'

时间:2012-01-29 19:41:50

标签: c# nhibernate fluent-nhibernate

我有以下代码段,其中我收到错误

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'.

1 个答案:

答案 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部分。