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.  [ 2 posts ] 
Author Message
 Post subject: Best way to retrieve just 2 columns to bind to combo
PostPosted: Sat Aug 19, 2006 1:50 am 
Newbie

Joined: Sat Aug 19, 2006 1:28 am
Posts: 5
I have a Contact class, comprised of ContactID, Name, Age, Prefix, Suffix, Email, Phone, Fax, etc., and I want to bind a list of all the contacts to a dropdown (DataTextField=Name, DataValueField=ContactID).

I can bind the dropdown datasource to "session.CreateCriteria(typeof(Contact)).List();", but that is inefficient as all of the fields are being returned.

I can use "session.Find("select c.ContactId, c.Name from Contact c");" to retrieve only the 2 fields needed to bind to the dropdown. But since this is just a generic IList, I would get error "DataBinding: 'System.Object[]' does not contain a property with the name 'Name'."

Another option is to create another class, say ContactLookup with only the ContactID and Name fields are mapped. But I rather not to have to create a derivative class just for binding to a dropdown.

Is there a more efficient and elegant solution?

Many thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 19, 2006 3:29 am 
Newbie

Joined: Sat Oct 15, 2005 3:30 am
Posts: 17
Hi,

I think you have provided all the options yourself.

Personally, I would just take option 1 and only optimize using option 3 *if* performance testing / user experience shows that getting all the columns is causing you grief.

It's probably far more likely that you will have more pressing performance issues in totally different parts of your application.

'Premature optimization is the root of all evil' etc etc

Cheers,

Adam.


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