How to get current NHibernate session object from ActiveRecord SessionScope Lock

I have an open ActiveRecord SessionScope Lock. I need to use an nhibernate session wrapped in SessionScope.

How can I get the current NHibernate session object from SessionScope?

Thanks so much for the answers.

[update] I have this code

ISession session = SessionScope.Current.GetSession( ); 

but i don't know how to go to getSession parameter

+6
source share
2 answers

I think SessionScope Activerecord can handle several factories for different types, but if you are not using this, I think it would be nice to go through in any type of class that is persistent:

 ISession session = SessionScope.Current.GetSession( typeof ( YourClass ) ); 
0
source

I solved this with this code:

  ISessionFactoryHolder holder = ActiveRecordMediator.GetSessionFactoryHolder(); ISessionScope activeScope = holder.ThreadScopeInfo.GetRegisteredScope(); ISession session = null; var key = holder.GetSessionFactory(typeof(ActiveRecordBase)); if (activeScope == null) { session = holder.CreateSession(typeof(ActiveRecordBase)); } else { if (activeScope.IsKeyKnown(key)) session = activeScope.GetSession(key); else session = holder.GetSessionFactory(typeof(ActiveRecordBase)).OpenSession(); } 
+9
source

Source: https://habr.com/ru/post/900688/


All Articles