views:

223

answers:

2

On properties inside my domain objects which I do not want lazy loading, I omit the virtual modifier, and also update the mapping file to reflect this using for example:

<property name="UserName" column="Name" type="String" length="40" lazy="false"/>

I would have though that setting the property lazy to false would make it accept that the relevant property inside the domain object not be virtual.

Can anyone explain how I can not make my eager load properties virtual I simply want:

public string UserName{
    get{ return _userName; }
    set{ _userName = value; }
}

Many Thanks,

Andrew

+1  A: 

I don't think properties can be lazy loaded -- just collections and references -- unless lazy loading by column was added recently.

I'm not sure what lazy="false" does on that property in NHibernate.

eyston
Its weird cause it complains that it wants the properties to be virtual.
REA_ANDREW
Yah. It makes all properties virtual because it wants to be able to lazy load the entity as a whole.
eyston
As an example ... Phone has a many-to-one with User. Phone is in the session, but User is lazy loaded. Phone.User.UserName would result in a database query to build the User object. This is why User.UserName has to be virtual.
eyston
Cheers for the explanation. :-)
REA_ANDREW
+1  A: 

http://davybrion.com/blog/2009/03/must-everything-be-virtual-with-nhibernate/

The following article explains the reason very clearly. Thanks for the input though. Appreciate it

REA_ANDREW