Lazy loading

In the beginning of the chapter we saw that when the Employee entity was loaded, NHibernate did not load the associated collection entities such as Benefits and Communities. That is default behavior of NHibernate. At first it may sound strange, but think what would happen if NHibernate tried loading Benefits and Communities along with the Employee entity. Each Community instance in the Communities collection has collection of the Employee instances associated with it. NHibernate will need to load all those Employee instances. Each of those Employee instances will have further Community instances to load. This cycle will only stop when the entire database is loaded into memory. To avoid situations like this, NHibernate only loads the ...

Get Learning NHibernate 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.