如何检查 NHibernate (HQL) 中的集合是否为空? [英] How to check if the collection is empty in NHibernate (HQL)?

查看:59
本文介绍了如何检查 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)

这篇关于如何检查 NHibernate (HQL) 中的集合是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆