Search text contains with QueryOver

混江龙づ霸主 提交于 2019-12-02 21:35:55
HatSoft

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%")

Miroslav Popovic

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')

var data = session.QueryOver<tablename>()    
                  .JoinQueryOver<if another table present>(x => x.Empsals)    
                  .WhereRestrictionOn(x => x.FName).IsLike("a%")        
                  .List<EmployeeDetails>();
WhereRestrictionOn(x => x.FName).IsLike("a%") use like this
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!