NHibernate 3.0搜索与子字符串 [英] NHibernate 3.0 search with substring
问题描述
我正在使用 NHibernate 3.0 IQueryOver进行搜索,其中有一个关键字用于搜索.我需要搜索一个字符串以查看它是否是字符串的一部分,
I'm making a search with NHibernate 3.0 IQueryOver, where I have a keyword for a search. I need to search in a string to see if it is part of the string,
Query().Where(e => e.Name.Contains(keyword)).List();
但是,这并没有完成预期的工作.应该如何进行这种搜索?
But this does not do the job as expected. How should such a search be performed?
推荐答案
我检查了NHibernate源,并且像上面发布的那样,ExpressionProcessor
中的QueryOver
字符串不支持Contains
.它支持的操作是IsLike和IsIn.您可以使用IsLike
,或者如果您热衷于Contains,请使用Linq.例如:
I checked the NHibernate source and the ExpressionProcessor
for the QueryOver
string like you posted above does not support Contains
. The operations it supports are IsLike and IsIn. You could either use IsLike
or if you are keen on Contains, use Linq. For example :
(from user in db.Users
where names.Contains(user.Name)
select user);
或
query.Where(person.Name.IsLike("%test%")) //In QueryOver
我猜您有一个"Unrecognised method call
"异常.
I am guessing that you got an "Unrecognised method call
" exception.
这篇关于NHibernate 3.0搜索与子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!