O'Reilly logo

NHibernate 3 Beginner's Guide by Gabriel N. Schenker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lazy loading properties

A new feature of NHibernate 3 is the ability to lazy load specific properties of an entity. This feature comes in handy whenever your entity has a property with potentially large content, such as a photo. Most probably, you won't need to always access the content of such a property if you work with the entity. It makes sense to not load the property by default and only load it whenever it is explicitly accessed by your code.

When using XML to define the mapping of an entity, we have the new lazy attribute on a property, as shown in the following code snippet:

<property name="SomeProperty" lazy="true" … />

However, we can also define lazy properties using Fluent NHibernate's fluent mapping API, as shown in the following code ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required