If you set lazy="false" on the class you do not need to do anything else. You will no longer see this issue since a proxy will not be created for you object.
You need virtual due to how NHibernate does lazy classes. Basically it created a proxy (using the Castle DynamicProxy) object which inherits from your class. Whenever it would have created your Order class for example, it creates an OrderProxy instead. Then it needs all properties and methods to be virtual since it wraps them in its own methods which first ensure that the object has been loaded and then calls your method. The only way to override your properties or methods to perform this check is if they are virtual.
Note that the decision to make all properties and methods as virtual is a mistake in my opinion. In the Java world everything is virtual by default unless you say otherwise. In the C# world it's the exact opposite. There is a minor performance hit to using virtual members, but it is not one that is likely to be noticed.
|