【发布时间】:2012-10-12 13:21:58
【问题描述】:
是否可以将 where 子句动态添加到 NHibernate 查询中?
我有一组子句,我需要循环遍历并在需要时添加 Where 子句 - 即,如果用户输入了多个搜索条件。
我可以写单个查询,没问题,像这样:获取所有以'a'开头的名称:
IEnumerable<Customer> customers = nHibernateSession.Query<Customer>().Where(x => x.Name.StartsWith("a")).ToList();
但我不知道如何添加另一个 where 子句 实际上我需要这样的东西:
foreach (clauses in SelectionClauses)
{
//add a .Where(Clause) to The Session.Query
}
我怀疑 nHibernateSession.Query 不能以这种方式使用... 有谁知道如何做到这一点?
【问题讨论】:
标签: nhibernate filtering nhibernate-criteria queryover