Please ask on the nh-users list instead. This list is about the development *of* NHibernate. A bit confusing, I'll admit.
2012/12/9 Tobias Eriksson <[email protected]>: > I am missing an efficient way in NHibernate to fetch several collections. > Say that you have a list of entities already in NHibernate session and want > to fetch two collections for these. You could do something like this. > > Session.QueryOver<MyEntity>() > > .Fetch(p => p.Collection1).Eager > > .WhereRestrictionOn(e => e.Id).IsInG(ids) > > .List(); > > Session.QueryOver<MyEntity>() > > .Fetch(p => p.Collection2).Eager > > .WhereRestrictionOn(e => e.Id).IsInG(ids) > > .List(); > > However this is fetching much more data than is needed, joining over the > main table several times. > > > > I have experimented with a strategy to only fetch the data that is necessary > (see code) > > Then you could do like this. > > > var fetcher = new CollectionFetcher(Session); > > fetcher.Fetch(entities, p => p.Collection1); > > fetcher.Fetch(entities, p => p.Collection2); > > Now I want to take it one step further and batch everything in one query > something like this > > var fetcher = new CollectionFetcher(Session); > > fetcher > > .Fetch(entities, p => p.Collection1) > > .Fetch(entities, p => p.Collection2) > .Execute() > > I have looked at how MultiQuery handles this and it seems quite easy to do, > but the methods on the Loader class is internal so I can’t access these from > outside of NHibernate. > > Does anyone have any ideas how I can take this idea further?
