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.  [ 4 posts ] 
Author Message
 Post subject: Subquery in select
PostPosted: Mon Feb 11, 2008 10:57 am 
Regular
Regular

Joined: Fri May 05, 2006 11:54 am
Posts: 51
Hi,

Is this type of query possible in NHibernate given the following SQL:

Code:
SELECT c.uid, c.surname, c.firstName,
(SELECT count(cc.uid) FROM calltreecontacts cc WHERE cc.contactUid = c.uid and cc.calltreecontactroleid = 1) as 'Plan Leader Count'
FROM Contacts c
ORDER BY c.surname, c.firstname


The 2 tables involved (Contacts and calltreecontacts ) map to NHibernate objects.

Is it possible to run such a query in NHibernate?

Cheers

Paul


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 13, 2008 10:52 am 
Regular
Regular

Joined: Fri May 05, 2006 11:54 am
Posts: 51
The answer to my question was the formula field.

I can simply add do the following in my mapping file:

Code:
<property column="planleadercount" type="Int32" name="PlanLeaderCount" not-null="false" formula="(SELECT count(cc.uid) FROM calltreecontacts cc INNER JOIN CallTrees ct ON cc.calltreeuid = ct.Uid WHERE cc.contactUid = Uid and cc.calltreecontactroleid = 1 and ct.deleted = 'false')"/>


How cool is that


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 14, 2008 1:23 am 
Beginner
Beginner

Joined: Fri Jan 12, 2007 1:08 am
Posts: 41
Yes, but it would be cooler if NHibernate supported lazy loaded properties because do you want to pay the price for the subquery every time you hydrate the object?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 14, 2008 3:57 am 
Regular
Regular

Joined: Fri May 05, 2006 11:54 am
Posts: 51
That would be very cool.

Has NHibernate any plans for this?

I know it is not in 2.0.


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

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.