it's possible to use dbdataadapter with nhibernate or reference the dbtransaction?

52 views
Skip to first unread message

kor

unread,
Nov 24, 2009, 11:59:22 AM11/24/09
to nhusers
hi all, i'm using nhibernate with firebird as database.

i'm using the transaction-per-request pattern.

in a place of my application i 'm using the DbDataAdapter ado.net
object.

my code is samething as

DbProviderFactory m_Provider = ***;
DataTable myTable = ***;
using (DbDataAdapter adapter = m_Provider.CreateDataAdapter())
using (DbCommandBuilder builder = m_Provider.CreateCommandBuilder())
{
builder.DataAdapter = adapter;
adapter.SelectCommand = (DbCommand)
Session.Connection.CreateCommand();
adapter.SelectCommand.CommandText = ***;

****
adapter.Update(myTable);
}

i'm calling this code with net remoting, my server object is exposed
in a web application on IIS.

The problem is that i'm opening a nhibernate transaction for every web
request so i need to set every DbCommand to that transaction
(Execute requires the Command object to have a Transaction object when
the Connection object assigned to the command is in a pending local
transaction).

The adapter will generate internally the DbCommands to update/delete
so i cannot use the NhbernateTransaction.Enlist method.

The unique solution that i find is to get a reference to the
dbtransaction used internally by nhibernate and set it
to the adapter.SelectCommand (the generate DbCommand will use the
same).

So there's a way to get a reference to the DbTransaction created by
nhibernate or do you have same suggestion to integrate the usage of
dbdataadapter/dbcommandbuilder and nhibernate?

thanks

kor

unread,
Nov 25, 2009, 3:17:14 AM11/25/09
to nhusers
sorry for the question, on the machine that i'm using today i can use
reflector and i see that enlist simply set the dbcommand.transaction
property so all works correctly.
Reply all
Reply to author
Forward
0 new messages