I know a lot has been said and posted about eager loading and lazy loading on NHibernate. I'v read all (lie!) the threads and posts and answers about why I should or should not use "lazy=false" while mapping or how to use HQL or Criteria to eager-load objects when I think is a good place to. Although, I haven't found anything about eager loading a collection property when I use the ISession.Get method. Let me explain the scenario:
I want to use a generic repository (base for all other specialized descendents classes), that would look like this:
class Repository<T>
{
public T GetById(long id)
{
using (ISession session = NHibernateHelper.OpenSession())
{
return session.Get<T>(id);
}
}
}
My question is: is there any way to use the generic "GetById" method (just like above) and even so use eager loaded all objects loaded in it?
I know some will answer "just use NHibernateUtil.Initialize", but for that I have to "know" my entity and, in that case, I will have to override my method and lose the generic advantage of my Repository. The same can be said about using HQL or Criteria or whatever other way that not using the simplicity of "Get". Besides, I would like to have the other advantages of Get (or Load) methods (because of this).
Any idea? Did I lose something? Don't I have annnyyy idea of what I'm talking about (quite possible)?