Mapping the prerequisites

Classes, as we defined in the previous chapter, cannot be used with NHibernate as is. There are some prerequisites that every class must satisfy before NHibernate is able to persist that class to database. Persistent classes must satisfy at least following two requirements:

  • Every attribute on class that NHibernate should save in the database has to be declared as one of public virtual, protected virtual, and protected internal virtual. This is to make the lazy loading feature work. Lazy loading is an important feature. We will look into it in detail in Chapter 6, Let's Retrieve Some Data from the Database, where we learn about retrieving entities from database. For now, it is worth mentioning that lazy loading only works ...

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.