QueryOver错误:表达式值中无法识别的方法调用 [英] QueryOver error : Unrecognised method call in expression value
本文介绍了QueryOver错误:表达式值中无法识别的方法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Nhibernate3.1中通过QueryOver查询
I have a query by QueryOver in Nhibernate3.1
var q = SessionInstance.QueryOver<Person>()
.Where(x => IsActive(x.PersonType) == true);
return q.List<Person>();
通过这种方法:
private bool IsActive(PersonType type)
{
if(type == PersonType.Employee
return true;
else
return false;
}
现在通过此消息出现运行时错误:
Now it has a runtime error by this message:
表达式值中无法识别的方法调用
Unrecognised method call in expression value
为什么?
推荐答案
我通过在谓词方法中返回表达式树而不是直接返回布尔值来解决了类似的问题.以您的示例为例:
I solved a similar problem by returning an expression tree in my predicate method instead of returning a boolean value directly. Using your example, it'd be something like this:
private Expression<Func<PersonType, bool>> IsActive()
{
return (t => t == PersonType.Employee );
}
这篇关于QueryOver错误:表达式值中无法识别的方法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文