i am using nhibernate profiler and seeing a few places where it is giving me a “Select n + 1” warning.
The obvious fix is to make some upfront eager joins but it got me thinking if in certain cases its actually simpler or faster to live with Select N + 1 compared to doing joins that may be load lots of data that you never actually use.
Your thinking is correct. In some cases, for example, all the root entities reference one or two instances of another entity. It might be faster to do 2 or 3 small selects instead of a denormalized one (i.e. with joins)
There is a way to make this convenient in almost all cases:
batch-size. If you set this attribute in both the entities and the collections to your usual page size, you’ll get a constant number of small selects (one per entity type).