-->
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: NHibernate Binding an IList from IQuery to a datalist
PostPosted: Fri Jul 25, 2008 12:27 am 
Newbie

Joined: Fri Jul 25, 2008 12:14 am
Posts: 2
I'm trying to return a list of dicussion title along with their number of replies, and bind to a datalist

IList imgIL = session.CreateSQLQuery(@"select count(*) as Dem,
img_album_name as Imgalbumname,
u.usr_username as Usrusername
from vnt_images i join vnt_image_albums al
on i.img_album_id = al.img_album_id
join vnt_users u on al.img_album_by = u.usr_id
group by i.img_album_id, al.img_album_name, u.usr_username
order by count(*) desc ")
.AddScalar("Dem", NHibernateUtil.Int32)
.AddScalar("Imgalbumname", NHibernateUtil.String)
.AddScalar("Usrusername", NHibernateUtil.String)
.SetMaxResults(6).List();

datalist1.DataSource = result;
datalist1.DataBind();

<asp:Datalist ID="datalist1" runat="server">
<ItemTemplate>
<%#Eval("Imgalbumname")%><br/>
<%#Eval("Usrusername")%>
</ItemTemplate>
</asp:Datalist >


The problem is <%#Eval("Imgalbumname")%>, <%#Eval("Usrusername")%> is not recongizable. I get an error

'System.Object[]' does not contain a property with the name 'Imgalbumname', 'Usrusername'

Anybody can help me out on this? How do I retrive the column values? Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 2:13 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You're query returns an array of objects[]:

object[] { dem, Imgalbumname, usrusername }

for each line of the result set. You need entities for a proper databinding. Try the AliasToBean result set transformer:

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/querysql.html#d0e9192

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 6:19 am 
Newbie

Joined: Fri Jul 25, 2008 12:14 am
Posts: 2
Thanks for replying and answering my question. It's done


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.