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.  [ 3 posts ] 
Author Message
 Post subject: IQuery mapping question
PostPosted: Thu Jul 19, 2007 4:41 am 
Newbie

Joined: Thu Jun 21, 2007 8:44 am
Posts: 4
I have created a query:

Code:
IQuery query = session.CreateQuery(
   "SELECT E.account.id, E.equipmentType.id, SUM(E.quantity) " +
   "FROM Entry AS E " +
   "WHERE E.when >=:startDate AND E.when <:endDate " +   
   "GROUP BY E.account.id, E.equipmentType.id");
   query.SetParameter("startDate", startDate.ToLongDateString());
   query.SetParameter("endDate", endDate.ToLongDateString());

   System.Collections.IList entries = query.List();


This returns a result as expected, but I need to access the collection columns directly to be able to read the results.

I would like to write
Code:
   System.Collections.IList<MyQuery> entries = query.List<MyQuery>();


How do I write a mapping file to handle this?

Cheers
Neil


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 1:32 pm 
Beginner
Beginner

Joined: Wed Nov 29, 2006 10:32 am
Posts: 34
NHIbernate does not return generic lists, but the "old" ILists which only return you an object.
So you have to do the cast yourself - either directly; or you write a wrapper about as follows:

Code:
static List<T> Generify<T>(IList li) {
   List<T> result = new List<T>();
   foreach (object obj in li) {
      result.Add((T) obj;
   }
   return result;
}


- which will of course fail if you call it with the wrong type ;-).

Regards
Harald


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 9:37 pm 
Regular
Regular

Joined: Tue Aug 08, 2006 4:28 am
Posts: 96
Location: Hong Kong
Neil, this thread http://forum.hibernate.org/viewtopic.php?t=972214 may have the answer for you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.