How to check if the collection is empty in NHibernate (HQL)?

微笑、不失礼 提交于 2019-12-25 04:37:23

问题


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

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?

Thank you!


回答1:


I think this syntax works here:

from stack s where exists elements(s.category)


来源:https://stackoverflow.com/questions/1105011/how-to-check-if-the-collection-is-empty-in-nhibernate-hql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!