I am using NHibernate. I want to use join on queryover, try following code but this gives error,
session.QueryOver(Of Messages)()
.Where(Function(x) x.UserID_Messages.Username.Contains(msgfrom))
.And(Function(x) x.Message.Contains(msg))
.And(Function(x) x.MsgDate >= startdate)
.List
But this error = Unrecognised method call: System.String:Boolean Contains(System.String) And if i try this query
session.QueryOver(Of Messages)
.JoinQueryOver(Of Users)(Function(x) x.UserID_Messages)
.WhereRestrictionOn(Function(x) x.Username).IsLike("%" & tosearch & "$")
.List(Of Messages)()
This result empty, even record is there in database. Please guide what am I doing wrong, or what is correct way to achieve this. Thanks
The .Contains
method, is a .NET method, which is not translated into SQL statement when using QueryOver
syntax. The second approach, with QueryOver
native method IsLike
is what we need. To be sure, that we will end up with a SQL like this:
username LIKE '%the searched value%'
we should use the built in MatchMode
.WhereRestrictionOn(Function(x) x.Username).IsLike(tosearch, MatchMode.Anywhere)
See the MatchMode class definition
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.