在 NHibernate 的 queryover 中使用 OR 子句 [英] Use OR Clause in queryover in NHibernate

查看:23
本文介绍了在 NHibernate 的 queryover 中使用 OR 子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Nhibernate.我正在通过 queryover 方法编写查询.我可以像下面的代码一样编写和子句.它的工作正常.

I am using Nhibernate. I am writing query through queryover method. I am able to write and clause as in code below. Its working fine.

db.QueryOver(Of Users)()
  .Where(Function(x) x.Role = "Guest")
  .And(Function(x) x.Block = 0)
  .And(Function(x) x.APPID = appId)
  .List();

但我想使用 Or 子句而不是 And 或两者的组合.我该如何实现这一点.谢谢

But I want to use Or clause instead of And, or combination of both. How can I implement this. Thanks

推荐答案

这里描述了我们如何使用 NHiberante 构建 OR

Here is description how we can build OR with NHiberante

语法(在 C# 中,正如标签所说) 是:

  • Restrictions.Or(restriction1,restriction1)
  • Restrictions.Disjunction().Add(restriction1).Add(restriction2).Add(...

在这种情况下,它可能是这样的(再次在 C# 中,而问题似乎使用 VB):

In this case, it could be like this (again in C#, while question seems to use VB):

db.QueryOver<Users>()()
  .Where((x) => x.Role == "Guest")
  .And(Restrictions.Or(
       Restrictions.Where<Users>((x) => x.Block == 0)
     , Restrictions.Where<Users>((x) => x.APPID == appId)
  ))
  .List<Users>();

这篇关于在 NHibernate 的 queryover 中使用 OR 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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