Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4033528
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:51:28+00:00 2026-05-20T11:51:28+00:00

I have an HQL query that returns projections of an entity including a count

  • 0

I have an HQL query that returns projections of an entity including a count of the a certain child collection.

select t.Id as TagId, t.Name as Name, count(elements(t.Documents)) as Count 
from Tag t
group by t.Id, t.Name, t.User
having t.User.Id = :userId"

It works except I need to place a condition on the count. I only want to count Documents where Trashed = false for the document.

I seem to have a mental block on how to do this. I am using NHibernate 3.0. I would be equally happy with ICriteria or Linq query.

UPDATE: Here is the fully correct query:

select t.Id as TagId, t.Name as Name, sum(case when d.Trashed = false then 1 else 0 end) as Count 
from Tag t
left join t.Documents d
group by t.Id, t.Name, t.User
having t.User.Id = :userId and sum(case when d.Trashed = false then 1 else 0 end) > 0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:51:29+00:00Added an answer on May 20, 2026 at 11:51 am

    IIRC, something like this should work (where d is an alias to the Documents collection):

    sum(case when d.Trashed = false then 1 else 0 end) as Count
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a following HQL query: SELECT s.id FROM stack s WHERE s.category is
I have the following HQL query which works fine, however it returns a list
I need to build an HQL query that uses the same entity twice, but
I have a HQL query that can generate either an IList of results, or
I have the following SQL query that works like a champ: select u.id from
You can also write hibernate hql or criteria queries. I have Teacher entity and
i want to format date to string in hql select, for example i have
I have a problem with a HQL query. I want to get all PID
I am trying to create an HQL query that will filter a tree based
Is it possible to write a HQL query that groups results by the discriminator

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.