1

当我做

Acc accountAlias = null;
var subQuery = QueryOver.Of<Temp>()
               .Where(x=>x.IsAccepted==null)
               .And(x=>x.Account.Id==accountAlias.Id);

var results = session.QueryOver<Acc>(()=>accountAlias)
              .Where(x=>x.User.Id==65)
              .WithSubquery.WhereExists(subQuery);

这将创建闲置的 sql:

select *
from Accounts a
where a.User_Id=65
and exists (
    select t.Account_Id
    from Temporary_Accounts t
    where t.IsAccepted is null and t.Account_Id=a.Account_Id)

如何添加或条件,NHibernate 将生成闲置的 sql:

select *
from Accounts a
where a.User_Id=65 
and (a.Amount = 100 or exists (
    select t.Account_Id
    from Temporary_Accounts t
    where t.IsAccepted is null and t.Account_Id=a.Account_Id))
4

1 回答 1

3

未经测试,但类似 ​​tihs 的东西可能会奏效

Acc accountAlias = null;
var subQuery = QueryOver.Of<Temp>()
               .Where(x => x.IsAccepted == null)
               .And(x => x.Account.Id == accountAlias.Id);

var results = session.QueryOver<Acc>(()=>accountAlias)
                  .Where(Restrictions.Disjunction()
                     .Add(Subqueries.WhereExists(subQuery))
                     .Add(x => x.Amount == 100))
                  .And(x => x.User.Id = 65)
                  .List();
于 2012-07-03T12:35:09.907 回答