如何检查 NHibernate (HQL) 中的集合是否为空?

问题描述:

我有以下 HQL 查询:选择 s.id从堆栈在哪里s.category 不为空

I have a following HQL query: SELECT s.id FROM stack s WHERE s.category is not empty

基本上,s.category 是到另一个表(Category)的一对多连接.我需要检查集合是否为空.我可以在 c# 代码中做到这一点(只需运行所有堆栈并检查 Stack.category.count > 0.是否有任何 HQL 方法可以这样做?

Basically, s.category is a one-to-many join to another table (Category). I need to check whether the collection is empty or no. I can do it in c# code (just run through all of the Stacks and check if Stack.category.count > 0. Is there any HQL way to do so?

谢谢!

我认为这个语法在这里有效:

I think this syntax works here:

from stack s where exists elements(s.category)