NHibernate Pitfalls: Lazy Scalar Properties Must Be Auto
This is part of a series of posts about NHibernate Pitfalls. See the entire collection here.
NHibernate supports lazy properties not just for associations (many to one, one to one, one to many, many to many) but also for scalar properties. This allows, for example, only loading a potentially large BLOB or CLOB from the database if and when it is necessary, that is, when the property is actually accessed. In order for this to work, other than having to be declared virtual, the property can’t have an explicitly declared backing field, it must be an auto property:
1: public virtual String MyLongTextProperty
7: public virtual Byte  MyLongPictureProperty
All lazy scalar properties are retrieved at the same time, when one of them is accessed.