Book Image

Learning NHibernate 4

Book Image

Learning NHibernate 4

Overview of this book

Table of Contents (18 chapters)
Learning NHibernate 4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 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 declare...