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 uand 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
UserSummaryDetailsobject and not a
Userobject, which would require him to rewrite methods that work on a
Userobject but only use a subset of fields (he mentions a
SendMailTomethod 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
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.