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
, andprotected 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 with virtual attributes of persistent classes. Having said that, let me also tell you that NHibernate is capable of working with private attributes as well, if the need be and we will look into that. But in most cases, you would not need to...