如何为 NHibernate 创建 OR 语句? [英] How to create OR statements for NHibernate?

查看:19
本文介绍了如何为 NHibernate 创建 OR 语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当为 NHibernate 创建条件时,所有条件都添加为 AND.

When creating a criteria for NHibernate all criteria are added as AND.

例如:

session.CreateCriteria(typeof(someobject))
.Add(critiera)
.Add(other_criteria)

那么最终结果将是

SELECT ...
FROM ...
WHERE criteria **AND** other_criteria

我想告诉 NHibernate 将条件添加为OR"

I would like to tell NHibernate to add the criterias as "OR"

SELECT ...
FROM ...
 WHERE criteria **OR** other_criteria

感谢任何帮助

推荐答案

您正在寻找 ConjunctionDisjunction 类,它们可用于组合各种语句形成 OR 和 AND 语句.

You're looking for the Conjunction and Disjunction classes, these can be used to combine various statements to form OR and AND statements.

AND

.Add(
  Expression.Conjunction()
    .Add(criteria)
    .Add(other_criteria)
)

.Add(
  Expression.Disjunction()
    .Add(criteria)
    .Add(other_criteria)
)

这篇关于如何为 NHibernate 创建 OR 语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆