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

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

问题描述

我使用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();



不过,我想用或者条款代替的,或两者的组合。我怎样才能实现这一点。谢谢

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

推荐答案

下面是描述我们如何与NHiberante建设或

Here is description how we can build OR with NHiberante

  • NHibernate QueryOver with WhereRestriction as OR

语法的(在C#作为标记表示)的是:


  • Restrictions.Or(restriction1,restriction1)

  • Restrictions.Disjunction()。添加(restriction1)。添加(restriction2)。新增(...

  • 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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