Generic query with NHibernate with eager loading
In my previous post, I showed how we could create generic methods to perform query, https://csharptipstricks.blogspot.com/2019/12/usage-of-expression-to-create-generic.html . However, the methods present there does not allow eager loading. In case you are wondering how eager loading is performed, see below. Do know that there are ways to assign eager loading during mapping, but I will not show it in this post. Method I : SessionFactory.OpenSession().Query<MyEntity>().Fetch(x => x.Property1).Fetch(x => x.Property2).ToList(); Method II : var tempMyEntityQuery = GetSession().Query<MyEntity>().Fetch(x => x.Property1).ToFuture(); GetSession().Query<MyEntity>().Fetch(x => x.Property2).ToFuture(); List<MyEntity> myEntityList = tempMyEntityQuery .ToList(); Both the methods above will eager load Property1 & Property2 in a single trip to the database. However, I would choose method I because a single statement (with left outer join)...