Using lazy properties
Consider a class representing a scientific article, with properties for author, title, abstract, full text, and so on.
This looks simple enough, but having the full article text stored in the entity could cause serious issues. The text may be several megabytes in size and if we're, for example, just listing the available articles, it's very unnecessary to load all that from the database and storing it in memory.
Thankfully, NHibernate has a solution for this, called lazy properties. Just as with lazy loading of referenced entities and collections, this function will not load the data until it is accessed.
Getting ready
Complete the Getting ready instructions at the beginning of this chapter.
How to do it…
Add a new folder named
LazyProperties
to theMappingRecipes
project.Add a class named
Article
to the folder:namespace MappingRecipes.LazyProperties { public class Article { public virtual int Id { get; protected set; } public virtual string Title { get; set;...