本文介绍了搜索文本包含 QueryOver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试这样做:

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

但我收到此错误:无法识别的方法调用:System.String:Boolean Contains(System.String)

你有什么想法吗?

更新:

public class Person
{
    public virtual string FirstName { get; set; }
    public virtual string LastName { get; set; }
}

推荐答案

NHibernate 没有此链接中提到的直接 C# 等效项 http://nhibernate.info/blog/2009/12/17/queryover-in-nh-3-0.html

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

其他限制

某些 SQL 运算符/函数在 C# 中没有直接等效项.(例如,SQL where name like '%anna%').这些运营商有Restrictions 类中 QueryOver 的重载,因此您可以编写:

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

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

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

这篇关于搜索文本包含 QueryOver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 13:13