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 を生成するという or 条件を追加するにはどうすればよいですか。

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 に答える