Nhibernate 使用QueryOver而不使用子查询的HQL大小
希望有人能回答这个问题 我知道我可以使用hql(下面的伪代码)执行以下操作 当Hql生产时Nhibernate 使用QueryOver而不使用子查询的HQL大小,nhibernate,Nhibernate,希望有人能回答这个问题 我知道我可以使用hql(下面的伪代码)执行以下操作 当Hql生产时 where ( select count(childcollection1_.ObjectA_Id) from [ChildCollection] childcollection1_ where objectA0_.Id=childcollection1_.ObjectA_Id and childcollection1_.D
where
(
select
count(childcollection1_.ObjectA_Id)
from
[ChildCollection] childcollection1_
where
objectA0_.Id=childcollection1_.ObjectA_Id
and childcollection1_.DTCreated between @p0 and @p1
)>0
干杯
坦齐
这就是您试图实现的目标吗?我编辑了一个问题,因为它不符合评论中的信息。您能解释一下为什么您试图生成完全相同的sql吗?sql server中的
执行计划
对于两个查询都是相同的。ChildCollection分配了一个筛选器,因此在HQL中使用size(ChildCollection)时,它包括已设置限制的会话筛选器。但是,使用QueryOver IsNotEmpty不会使用此会话筛选器。
var query = QueryOver.Of<ObjectA>()
.WhereRestrictionOn(x => x.ChildCollection).IsNotEmpty();
WHERE
exists(
select
1
from
[ChildCollection]
where
this_.Id=ObjectA_Id
);
where
(
select
count(childcollection1_.ObjectA_Id)
from
[ChildCollection] childcollection1_
where
objectA0_.Id=childcollection1_.ObjectA_Id
and childcollection1_.DTCreated between @p0 and @p1
)>0
var query = QueryOver.Of<ObjectA>().WhereRestrictionOn(x => x.ChildCollection).IsNotEmpty();
SELECT this_.Id
FROM [ObjectA] this_
WHERE exists(select 1 from [ChildObjectB] where this_.Id = [key])