transactions - DbTransaction and DbConnection when working with EF4 -
i'm trying implement unif of work around objectcontext of ef4 in web application. uow httpmodule. need current transaction connection. when http request first commes start transaction on objectcontext context.connection.begintransaction(). on request end need retrieve current transaction connection there no property on connection object. made following code achieve doesn't work.
private dbtransaction gettransaction() { if (_currenttransaction == null) { var command = getsession().connection.createcommand(); // current transaction if (command.transaction != null) _currenttransaction = command.transaction; else _currenttransaction = getsession().connection.begintransaction(); } return _currenttransaction; }
i don't understand why command.transaction is null. if try getsession().connection.begintransaction() exception transation exists , can't start several transactions in parrallel.
getsession() retrives current ef objectcontext httpcontext.current.items. objectcontext stored there on beginrequest.
if give me guidance appreciate.
thanks.
objectcontext.connection
isn't store connection; it's entityconnection.
you want transactionscope
. if want start transaction on store only, want ((entityconnection)context.connection).storeconnection
.
Comments
Post a Comment