Aaron (Eleutian) and Oren (Ayende) have a little back–and–forth going about optimizing NHibernate. I’m no expert on NHibernate, but I do have experience with O/R mappers and even more experience with raw databases and SQL, and on techniques for improving performance on both, so I feel I could chime in at least in one area of their debate…
Partial object queries
Let me bring you up to date:
- Aaron wants to run an NHibernate query of
select u(Username, Email) from User u
and get a User object with only those two fileds filled in. - Oren says you can do it:
select new UserSummaryDetails(u.Username, u.Email) from User u
. - Aaron disputes that as a solution, since it returns a
UserSummaryDetails
object and not aUser
object, which would require him to rewrite methods that work on aUser
object but only use a subset of fields (he mentions aSendMailTo
method which uses only the username and email).
There’s a solution that perhaps can perhaps make both happy. You specify an interface (IEmailInfo
) that exposes the Username
and Email
properties, implement that interface in your User
and UserSummaryDetails
classes, and use the interface on your SendMailTo
method? At least, this seems plausible considering my limited (but growing) NHibernate exposure, and would work in other O/R mappers (like Paul Wilson’s).
Either way, keeping up with the aforementioned blog debate is a good way to understand the inner workings of NHibernate.