Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search text contains with QueryOver

Tags:

I'm trying to do this :

var list = Session.QueryOver<Person>()     .Where(x => x.LastName.Contains(searchText))     .List<Person>(); 

but I get this error : Unrecognised method call: System.String:Boolean Contains(System.String)

Do you have an idea ?

Update :

public class Person {     public virtual string FirstName { get; set; }     public virtual string LastName { get; set; } } 
like image 927
Kris-I Avatar asked Jul 22 '12 15:07

Kris-I


2 Answers

NHibernate does not have direct C# equivalent as mentioned on this link http://nhibernate.info/blog/2009/12/17/queryover-in-nh-3-0.html

Additional Restrictions

Some SQL operators/functions do not have a direct equivalent in C#. (e.g., the SQL where name like '%anna%'). These operators have overloads for QueryOver in the Restrictions class, so you can write:

.Where(Restrictions.On(c => c.Name).IsLike("%anna%"))

There is also an inline syntax to avoid the qualification of the type:

.WhereRestrictionOn(c => c.Name).IsLike("%anna%")

like image 135
HatSoft Avatar answered Sep 19 '22 16:09

HatSoft


Looks like QueryOver doesn't support Contains method. You could try with IsLike restriction:

nhibernate queryover LIKE with expression trees
NHibernate 3.0 search with substring
queryover and (x like 'a' or y like 'a')

like image 39
Miroslav Popovic Avatar answered Sep 20 '22 16:09

Miroslav Popovic