I have an open Castle ActiveRecord SessionScope. I need to use the nhibernate session wrapped into SessionScope.
How can i retrieve the current NHibernate Session Object from SessionScope?
thank you very much for the replies.
[update] i have this code
ISession session = SessionScope.Current.GetSession( );
but i don't know what pass to the GetSession parameter
I resolved it 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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With