Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
315 views
Welcome To Ask or Share your Answers For Others

1 Answer

Here is description how we can build OR with NHiberante

The syntax (in C# as the tag says) is:

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...