1
votes

Im new in Nhibernate. I have application with lazy loading. I want to write method

public User GetUser(int id)

in my UserPersister class. Later, in application I want use some referenced property like User.Role or User.Address. It wan`t work if I close Session that I used to retreive user. My first idea was to create Singleton Session and I will be able to get all data then. I read some articles that it is bad idea becouse of performance and memory leaking. Is it true? What is the solution of this problem ?

Regards Martin

2
It mostly depends on type of application you are building. Is it some WinForms / WPF application or Web application? - Ladislav Mrnka

2 Answers

0
votes

Have a look at Effectus for a simple approach to WPF + NHibernate.

0
votes

First of all remember that NH session != sqlconnection. Having global (singleton) session is generally not good idea even in wpf because you can reach multithread scenario sooner or later. But i definitelly wouldn't argue against with performance nonsense in your case. I would suggest you to open it for shortest possible time to complete the usecase. Perform kind of analysis where you identify usecases of your app as "sessions" with limited lifespan. For example shopping cart. You start and you finish. You can make session live until you finish such usecase. Then throw it away...