Pregunta

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

¿Fue útil?

Solución

I think that the Activerecord SessionScope can handle multiple factories for different types, but if you are not utilizing that I think you would be good to pass in any type of class that is a persisted one:

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

Otros consejos

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();
        }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top