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.
|