我可以从NHibernate获取基础连接和事务对象吗?

Jon*_*len 2 c# sql nhibernate

是否可以从NHibernate事务中获取DbConnectionDbTransaction对象?

我需要将某些NHibernate调用与同一事务中的第三方库结合在一起。

Jon*_*len 6

ISession.Connection返回IDBConnection对象。有关交易,请参见下面的博客文章。

    //http://ayende.com/blog/1583/i-hate-this-code

    private static IDbTransaction GetTransaction(ISession session)

    {
        using (var command = session.Connection.CreateCommand())
        {
            session.Transaction.Enlist(command);
            return command.Transaction;
        }
    }
Run Code Online (Sandbox Code Playgroud)