Humble Blog

Monday, August 8, 2011

NHibernate is testable too

On my last post regarding Entity Framework is infinitely testable, we can also do that on NHibernate too. We just need to suppress NHibernate from performing its fetching function when the provider of the given IQueryable is not of NHibernate type.

The code above can work on aggregate root only, i.e. it can only fetch the children and parent of a given aggregate root, but it cannot further fetch the grandchildren of an aggregate root; ThenFetch and ThenFetchMany can only be chained after Fetch and FetchMany.

If we can find how to cast IQueryable to NHibernate's INhFetchRequest<TOriginating, TRelated>, then we can include unit testing-friendly extension methods for grandchildren entities