Login

Username

Password





Register   Reset password

This is a read-only archive of the forum.

# mpw 3/6/2006 8:20 AM
Is there a way of getting NHibernate to return part of a class?
If you have a customer class mapped to the customer table and you want to get the ID and Surname for all customers, to produce a lookup list, but you don't need the rest of the table.

HQL - "Select s.ID, s.Surname from Customers s" produces an IList of ILists"

- I know you guys have more experience than me on NHibernate and I can't find an answer to this on their forums ;) - Pulling entire tables when you only want a subset of data seems rather inefficient. I can see several workarounds but they involve redesiging the data structure and/or the classes.

Thanks
Mark
# martijnb 3/6/2006 9:50 AM
mpwIf you have a customer class mapped to the customer table and you want to get the ID and Surname for all customers, to produce a lookup list, but you don't need the rest of the table.

HQL - "Select s.ID, s.Surname from Customers s" produces an IList of ILists"

That's the correct syntax. It produces an IList of object arrays and is perfectly usable in ASP.NET pages. Only issue is that you have to access the objects by index instead of name.
Pulling entire tables when you only want a subset of data seems rather inefficient. I can see several workarounds but they involve redesiging the data structure and/or the classes.

Well, I always try to find a compromise. In this case I prefer ease of use to sqeezing the last bit of performance out of the system, so I'm just binding complete objects (haven't had any issues with that yet).
Mostly, when I query specific fields, it is because I need some aggregation.
# mpw 3/6/2006 11:53 AM
martijnbThat's the correct syntax. It produces an IList of object arrays and is perfectly usable in ASP.NET pages. Only issue is that you have to access the objects by index instead of name.
Sure but unless I'm missing something that doesn't help binding to a listbox where you need to set the datatextfield and the datavaluefield.

You're right it's probably not worth the effort to save 5k per row x 20 rows.

Thanks
Mark
# mpw 3/6/2006 3:32 PM
Martijnb

Definitely not worth the effort!
There are trivial solutions to these control binding issues.

When I finish this module in the next day or so is there somewhere you would like us to submit them?

Mark