I don't understand what you mean with "I did lazy loading". Lazy loading is a feature, it is turned on by default and you can turn it off if you don't like it.
There are two kinds of lazy loading: for references to other entities and for lists.
Given this entity:
class Entity
{
// pk
int id { get; private set; }
// reference to another entity
User MyUser { get; set; }
// list to other entities
IList<Comments> MyComments { get; set; }
}
Lazy loading on the reference to User
If you have lazy loading on the User, you need to define all members of the User class virtual. NHibernate will create a so called proxy. The proxy is a classed defined at runtime which derives from User. Your code is accessing it as User and is not aware that is is a subclass. But when you access one of its members the first time, the properties are loaded from the database.
If you want to turn off lazy loading on the User class, you need to do this in its mapping:
<class name="User" lazy="false"> ...
Then NHibernate creates always instances of type User, no proxies. You don't need to have anything virtual.
Lazy loading on the list of comments
If you use lazy loading on the list of comments, it is the list itself that implements the lazy loading. If you access the list the first time, it is loaded from the database. NHibernate uses a list that implements IList, but is not List.
If you want to turn off lazy loading in the list, you do this in the mapping of Entity:
<class name="Entity">
<bag name="MyComments" lazy="false" >
...
Usually, lazy loading is a good thing, and you application does not have to care about it much. But there are some risks. For instance, if you serialize a instance, and it is a proxy, you get a not initialized proxy instead of anything useful. Lazy loading only works as long as the session is open. It is not always faster to use lazy loading. If you need to load all the data anyway, its faster to load it in one piece.
So the configuration needs to be done carefully.
Edit:
To answer your original question: Is lazy loading required for NHibernate? No. But: Is lazy loading required in my application? Most probably yes.
I think, only small and rather trivial applications don't need lazy loading. If you have a system with many persistent classes, you'll need lazy loading.
Entities themselves should not have the responsibility of lazy loading. That is an infrastructural concern whose solution will lie elsewhere.
Let's say an entity is used in two separate contexts. In the first, its children are used heavily and are eagerly-loaded. In the second, they are used rarely and are lazy-loaded. Is that also the entity's concern? What would the configuration look like?
NHibernate answers these questions by proxying the entity type. A property of type IList<Entity>
is set by the infrastructure to an implementation which knows about lazy loading. The entity remains blissfully unaware. Parent references (like in your question) are also handled, requiring only a simple property.
Now that the concern is outside the entity, the infrastructure (ORM) is responsible for determining context and configuration (like eager/lazy loading).
Best Answer
It's called lazy loading because, like a lazy person, you are putting off doing something you don't want to. The opposite is Eager Loading, where you load something right away, long before you need it.
If you are curious why people might use lazy loading, consider an application that takes a LOOOOONG time to start. This application is probably doing a lot of eager loading... loading things from disk, and doing calculations and whatnot long before it is ever needed.
Compare this to lazy loading, the application would start much faster, but then the first time you need to do something that requires some long running load, there may be a slight pause while it is loaded for the first time. Thus, with lazy loading, you are amortizing the load time throughout the course of running your application... and you may actually save from loading things that the user may never intend to use.