0100110010101
0100110010101

Reputation: 6729

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

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!

Upvotes: 0

Views: 2528

Answers (1)

David M
David M

Reputation: 72890

I think this syntax works here:

from stack s where exists elements(s.category)

Upvotes: 1

Related Questions