Hello,
As implied by other answers, lazy-loading can not work if there is no 
opened NHibernate session when the entity try to load the lazy property. 
Furthermore, if the NHibernate session having loaded the entity has been 
closed, re-opening an other one before accessing entity lazy property is 
not enough. You should also attach the entity to the new NHibernate 
session. (With ISession.Update(entity): it does re-attach the entity, it is 
not at all a sql update.)

As you seem to use your User entity in a custom membership provider, you 
may not be willing to add some NHibernate session handling logic inside 
your provider to handle for cases where roles collection has not been 
already loaded.
A usual recommendation would be to transfer your user and roles data to 
non-mapped classes before the NHibernate session get closed, and use those 
non-NHibernate classes inside your membership provider.
But it will not suit your needs if you want the lazy loading to occur only 
when the provider is being queried for user's roles.

Maybe you can overcome this by studying your membership provider life-cycle 
and adjust your NHibernate session strategy for having its lifespan 
covering the lifespan of your membership provider. It could be a viable 
option if your membership provider instances lifespan are limited to the 
request lifespan. Otherwise, I guess you would only have the choice between 
giving up lazy-loading inside membership provider, or reattaching your user 
entity to a NHibernate session inside your provider prior to use its roles 
property.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to