-->
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: How to display entities in a DataGrid (part 2)
PostPosted: Mon May 23, 2005 7:02 am 
Newbie

Joined: Wed May 18, 2005 1:28 am
Posts: 5
Location: Depok, Indonesia
I'm back ... with similar problems ... :D

From previous discussion about the same subject, I have one tiny curiosity. I think I'll post some codes below.

Please assume that these codes below is executed after a successful configuration of NHibernate and opening a session.

Code:
lst = session.Find("SELECT q FROM Question q join fetch q.Asker_ID m");

this.dgTest.DataSource = lst;
this.dgTest.DataBind();


Question is a persitent object having a many-to-one relationship with Member (the foreign key is Asker_ID)

Note:
- lst is an IList
- dgTest is a DataGrid; the columns are auto-generated

The code resulted in showing ALL (sorry about the caps) properties of each Questions posted by the corresponding Member, except for the foreign key, i.e. Asker_ID.

Next, I modified the code so the DataGrid will only show me the Subject of each Questions.

Code:
lst = session.Find("SELECT q.Question_Subject FROM Question q join fetch q.Asker_ID m");

this.dgTest.DataSource = lst;
this.dgTest.DataBind();


It's a clear success. But ... here comes the first Question.

The second question won't be a problem in an auto-generate-column DataGrid. But what if you want to add a BoundColumn. How do you refer to the "q.Question_Subject" for the Data Field?

The obvious work-around would be selecting only "q", then add "Question_Subject" as the Data Field of the bound column.

Why am I asking this, because I believe it took more resource to get all the properties of a persistent object from the Database instead of just one column. Any comment on this?

Next, I modified the code again. This time I want the DataGrid to show me the ID of each Questions and the ID of the Member who posts the Question.

Here's my code:

Code:
lst = session.Find("SELECT q.ID, m.User_ID FROM Question q join fetch q.Asker_ID m");

this.dgTest.DataSource = lst;
this.dgTest.DataBind();


Now, my DataGrid seems to show me properties of an array. (I've talk about this in my previous post with the same subject).

After debugging, I found out the difference between the lst from those three codes above.

The 1st one resulted in an array of Question. The 2nd one resulted in an array of String (cmiiw). The 3rd one is an array of array of String (again, cmiiw).

It's obvious that I cannot use an array of array of something directly as a datasource for a DataGrid.

So, the second question is ... How do you convert an array of array of something into an array of something? Or maybe, Why does NHibernate returns an array of array of something if the "SELECT" clause select more than one item?

I hope I made my points clear enough.

Thank you.

_________________
-Adin


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 2:17 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
adin05 wrote:
Why does NHibernate returns an array of array of something if the "SELECT" clause select more than one item?

Well, it's sort of natural, how else do you want it to return the multiple results? You can also use "select new SomeObject(args)", it will return you a list of SomeObjects constructed using args.

But your problem is different - you were almost there when you had all the properties of Question visible, except for the Member. Now you only have to forgo using the autogenerated columns and add the columns yourself, I think. So add all the properties of Question, and try adding a property of Member using "Asker_ID.SomeProperty" syntax.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2005 9:42 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Why don't you use something like :

Code:
SELECT q.ID, q.AnyData, q.User.User_ID, q.User.Name FROM Question q


It will gives you an array of arrays, each containing a row of data you want to display in your grid.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


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.