These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Criteria Query
PostPosted: Thu Aug 23, 2007 3:11 am 
Newbie

Joined: Thu Aug 23, 2007 2:56 am
Posts: 1
Hi all,

I've got two tables in my db Projects and Reports. Each Project instance keeps collection of reports. I'm using criteria query to filter projects set so I can easily build dynamic query based on Projects properties. I would also like to query Projects table based on Reports properties. For instance I want to get all projects with ALL reports having some particular status. I'm doing this like:

Code:
Criteria.Add(Expression.Sql(QUERY_ALL_REPORT_BY_STATUS, reportStatus, NHibernateUtil.Int32));


where

Code:
protected const string QUERY_ALL_REPORT_BY_STATUS =
        "(select count(Id) from reports where ProjectId = {alias}.Id and StatusId = ?) = (select count(Id) from reports where ProjectId = {alias}.Id) and (select count(Id) from reports where ProjectId = {alias}.Id) > 0";


I don't even know how to use aliases in tis query. I'm shure that there is some better way to solve this issue.

Waiting for any suggestions.
Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.