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

查看:135
本文介绍了如何为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将标准添加为或"

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

OR

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

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

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