当我这样做的时候
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将生成FlowingSQL语句:
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))发布于 2012-07-03 20:35:10
未经过测试,但像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();https://stackoverflow.com/questions/11310858
复制相似问题