Page 1 of 1

Does LINQ to SQL provider for Oracle support transactions?

Posted: Tue 22 Dec 2009 21:44
by rdrenker
I've been trying trying to create a transaction to commit / rollback stored procedure calls using the LINQ to SQL provider, but haven't been able to get it work.

I've been trying this type of code without success:

--------

using (TestDataContext context = new TestDataContext(ConnectionString))
{
context.Connection.Open();
context.Transaction = context.Connection.BeginTransaction();

context.SomeSprocToInsertData(data1, data2, data3);

context.Transaction.Rollback();
}
-------


The sproc runs, the data is inserted...And the Rollback is completely ignored.

Are transactions supported? If so, what am I doing wrong?

Thanks,

Roy

Posted: Wed 23 Dec 2009 13:53
by AndreyR
This behaviour is caused by the fact that every procedure call is executed on the new connection by default.
It is designed for the performance reasons.
As a solution, you can simply set the DataContext.MaxUsedConections property to 1.
This will force the usage of the single connection, and the transaction will be rolled back.