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; } }
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%")
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With