0

As you see,what would happen if I use WcfOperationSessionContext in the non-WCF scenario?

Any answer will be helpful! Thanks!

Lyon Gu
  • 23
  • 8

1 Answers1

1

In this case the self descriptive name WcfOperationSessionContext could not tell you more. This session context implementation is only for WCF scenario.

If you need more take a look on the implementation here:

The class summary:

/// <summary>
/// Provides a <see cref="ISessionFactory.GetCurrentSession()">current session</see>
/// for the current OperationContext in WCF. 
/// Works only during the lifetime of a WCF operation.
/// </summary>
public class WcfOperationSessionContext : MapBasedSessionContext
...

Take a look on the others to get more understanding what would suite to you in your multi-thread environment:

One of thread session context will be better choice

But as you can read in documentation 2.3. Contextual Sessions, it is always up to you to bind and unbind ISession instance:

  • NHibernate.Context.ThreadStaticSessionContext (...) You are responsible to bind and unbind an ISession instance with static methods of class CurrentSessionContext.

  • NHibernate.Context.WcfOperationSessionContext (...) You are responsible to bind and unbind an ISession instance with static methods of class CurrentSessionContext.

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • Thanks.Sorry for my stupid Description.Actually,I want to know in multi-thread environment,**ThreadStaticSessionContext** maybe result **multiple threads has the same session** and WcfOperationSessionContext would result that **too**? – Lyon Gu Jan 29 '13 at 07:37
  • 1
    If you get the same session for multiple threads, then you are doing something wrong. The Context's will hold the sessions, but it's still your responsibility to bind and unbind them properly. – Oskar Berggren Jan 29 '13 at 07:43
  • Lyon Gu: NO, the essence of ThreadStatic session context is, that every thread is keeping its Session instance. Only that thread is working with it. But you still have to manage its bind and unbind operations. Read this for more http://stackoverflow.com/a/855602/1679310. – Radim Köhler Jan 29 '13 at 07:44
  • @Radim Köhler:Thanks.I have some misunderstanding about ThreadStatic session context.And the link is also very helpful:) – Lyon Gu Jan 30 '13 at 02:15
  • @Oskar Berggren:Thanks.I've done the wrong thing...Very helpful.:) – Lyon Gu Jan 30 '13 at 02:24