Hi Victor,

>  This isn´t the solution that I'm searching, because i have to make a copy, 
> but if NHibernate can´t provide another solution like detaching and object 
> and turn it into a simple POCO, this is a possible patch.

I suspect this is the correct way (for you) to go.



>  Another possibility is manipulate the code of NHibernate, adding a new 
> property to the SessionFactory and modifiying the code to avoid the throw of 
> the LazyLoadingException if this flag is enabled and the Entity is detached


Fabio’s original response was to ask what the concept should be here?

I you have a Book with a property Author that is lazy loaded, what should NH 
do, and when?

1.  You load a Book, and it has an Author proxy that is not loaded;
2.  You close the session.

Are you suggesting that this ‘setting’ would make the book.Author incorrectly 
return null at step 1 when the book is loaded?
Are you suggesting that this ‘setting’ would change the the book.Author to 
<null> at step 2?
Are you suggesting that this ‘setting’ would allow you to access the 
book.Author after step 2, not throw an exception, but return nulls for all 
other unavailable properties?  (e.g., book.Author.Age would be what ... 0?)

None of these sound wonderful to me ... in each of these suggestions your 
entities will silently return incorrect information.

I don’t know if that is of any help.  For some additional reading, it might be 
worth reading this to check your world-view of how you want your app to behave 
matches the design concepts behind NH (like lazy-load, identity-map etc):  
http://unhandled-exceptions.com/blog/index.php/2010/03/23/how-do-you-think-about-the-problem/
 

Richard


From: Victor Mingueza 
Sent: Monday, October 31, 2011 10:19 AM
To: [email protected] 
Subject: Re: [nhibernate-development] Re: Disabling LazyInitializationException
Yes, it can be helpful for me. 

The problem that i have with AutoMapper or the process of serialization is that 
can´t control if a property is loaded previously. These automated process get 
the value of Lazy items with a LazyLoadingException if session is closed or 
loading objets that don´t want to pass to other layers with possible circular 
references.

  Implementing a method using reflection with the 
NHibernateUtil.IsInitialized(), like says Fabio (TEntity TransformToDto(TEntity 
entity)) I can control the access of this properties and create a copy of this 
instance like a DTO and work with it and serialize with only the previusly 
loaded properties.

  This isn´t the solution that I'm searching, because i have to make a copy, 
but if NHibernate can´t provide another solution like detaching and object and 
turn it into a simple POCO, this is a possible patch.

  Another possibility is manipulate the code of NHibernate, adding a new 
property to the SessionFactory and modifiying the code to avoid the throw of 
the LazyLoadingException if this flag is enabled and the Entity is detached

Reply via email to