NHibernate with IQueryOver-使用子查询和或条件创建where条件
当我这样做的时候NHibernate with IQueryOver-使用子查询和或条件创建where条件,nhibernate,subquery,criteria,queryover,icriteria,Nhibernate,Subquery,Criteria,Queryover,Icriteria,当我这样做的时候 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)
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);
如何添加NHibernate将生成休闲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)
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))
未经测试,但类似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();
Acc accountAlias=null;
var subQuery=QueryOver.Of()
。其中(x=>x.IsAccepted==null)
和(x=>x.Account.Id==accountAlias.Id);
var results=session.QueryOver(()=>accountAlias)
.Where(限制.析取()
.Add(子查询.WhereExists(子查询))
.Add(x=>x.Amount==100))
.和(x=>x.User.Id=65)
.List();