Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get the underlying conneciton and transaction objects from NHibernate?

Tags:

c#

sql

nhibernate

Is it possible to get the DbConnection and DbTransaction objects from a NHibernate transaction?

I need to combine some NHibernate calls with a third-part library inside the same transaction.

like image 641
Jonathan Allen Avatar asked Oct 25 '25 05:10

Jonathan Allen


1 Answers

ISession.Connection returns the IDBConnection object. For the transaction see the blog post below.

    //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;
        }
    }
like image 100
Jonathan Allen Avatar answered Oct 27 '25 19:10

Jonathan Allen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!