Is Lazy Loading required for nHibernate?

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.

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 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. Nbernate 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: ... Then Nbernate 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.

Nbernate 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: ... 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 N 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.

The NH reference doc completely contradicts itself with "Since lazy initialization can lead to bugs ..., non-laziness is the default. " and "Nbernate uses lazy select fetching for collections and lazy proxy fetching for single-valued associations. " - for collections – Chris S Aug 11 at 23:03 @Chris: The first sentence is old.

Lazy is default since version (i-dont-know). The second statement is what I actually tried to explain. – Stefan Steinegger Aug 18 at 6:38.

If you're using hbm. Xml files for you mapping simply adding a lazy="false" to the element will get you non-lazy loading for all simple properties. Foreign entities will still be lazy by URL1 make them eager add lazy="false" to the mapping element.

One benefit of eager loading is you will no longer need virtual properties on your entity classes. Edit: If you really want to find out what's going on behind the scenes, Nbernate logs everything using log4net. Adding inside in your web.

Config will spit all the SQL Nbernate generates the file c:\logs\sql.log.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions