I'm having a few problems with Eager Loading in NHibernate. The first thing I've noticed when starting to maintain this application is they don't seem to eager load anywhere.
My first port of call was Fetch. But this threw an exception saying that it cannot complete that operation when the collection is an IList. Apparently it has to be an ICollection. I can hardly change the domain, just to accommodate Fetch.
Next up, I looked at .Future and .FutureValue. No go there as the provider did not support it.
This left me with NHibernateUtil.Initialize. As a proof of concept, I wrote some code like:
var leppp = _repository.Query<LogbookEntryProcedure>()
.Where(lep => lep.LogbookEntry.Id == logbookEntryId);
NHibernateUtil.Initialize(leppp.Select(l => l.Complications));
NHibernateUtil.Initialize(leppp.Select(l => l.Magnitude));
NHibernateUtil.Initialize(leppp.Select(l => l.Outcome));
NHibernateUtil.Initialize(leppp.Select(l => l.FollowUps));
var lepp = leppp.Single();
It did not throw an exception. However, it did not seem to eager load anything. When I looks at Profiler, I could see that round trips were being made to the database for the related objects.
So, how does one do eager loading in NHibernate in these circumstances?