views:

111

answers:

1

hello,

i'm trying to understand how and if its possible to keep a session open on a wcf service.

the problem is that if i select an entity and pass it to the client and than return it to the server with the same session, i get an exception cause session dont know this entity any more (the reference changed because of wcf).

so i have to open a new session for updates, when i open a new session i loose the greate cache mechanizm of nhibernate.

what can i do to solve this?

i want to keep the cache i dont care if i need to open session for each call.

+1  A: 

Typically you would use a session per call with wcf. When you receive your entity back from the client you should be able to call Session.Merge( entity) and do the work you need.

Aaron Fischer
but why(session per calll)? i don't wanna loose cache...
Chen Kinnrot
You can work with your second level cache that is per sessionFactory but a session should be tied to a short lived unit of work. In wcf the call would be your unit of work. You could close the session and store it somewhere for next time(reopen the session) but managing session life span between wcf calls will not be fun.
Aaron Fischer
where can i read about this second level cache??
Chen Kinnrot
the documentation is here http://nhforge.org/doc/nh/en/index.html#performance-cache also take a look at http://ayende.com/Blog for lots of good info. And Davy has a quick start http://davybrion.com/blog/2009/02/quickly-setting-up-and-using-nhibernates-second-level-cache/
Aaron Fischer