I can't reproduce it. This test succeeds:
[Test]
[ExpectedException(typeof(ApplicationException))]
public void ExternalTransactionFailTest()
{
DataAccessAdapter adapter = new DataAccessAdapter();
try
{
adapter.StartTransaction(IsolationLevel.ReadCommitted, "TestTran");
// first save a customer.
CustomerEntity newCustomer1 = EntityCreator.CreateNewCustomer(1);
newCustomer1.TestRunId = _testRunID;
AddressEntity newAddress = EntityCreator.CreateNewAddress(1);
newAddress.TestRunId = _testRunID;
newCustomer1.VisitingAddress = newAddress;
newCustomer1.BillingAddress = newAddress;
bool result = adapter.SaveEntity(newCustomer1);
// second save of a customer, this should fail.
CustomerEntity newCustomer2 = EntityCreator.CreateNewCustomer(2);
newCustomer2.TestRunId = _testRunID;
newCustomer2.VisitingAddressId = 999;
newCustomer2.BillingAddressId = 999; // not there, will fail.
result = adapter.SaveEntity(newCustomer2);
adapter.Commit();
}
catch(ORMQueryExecutionException ex)
{
adapter.Rollback();
throw new ApplicationException("Transaction failed", ex);
}
catch(Exception ex)
{
throw ex;
}
finally
{
adapter.Dispose();
}
}
which more or less mimics what you're doing.
Dispose performs a rollback only if the transaction isn't rolled back / committed yet. Rollback and Commit both call Reset, which resets the transaction and all its parameters. Dispose then sees no transaction in progress and doesn't perform the rollback.
So I'm a bit confused what's going on. Silly question: is your service build with the wrong version (i.e.: .NET 1.0 ) of the ormsupport classes instead of the .NET 1.1 version?
(edit). I see you do:
MyAdapter.SaveEntity(e1)
dim e2 as new Entity2Entity
e2.foreignkey=e1.primarykey
This gives an ORMEntityOutOfSyncException, as you save e1 without fetching it back. So the second save never happens. When I change:
newCustomer2.VisitingAddressId = 999;
into
newCustomer2.VisitingAddressId = newCustomer1.VisitingAddressId;
I do the same as you do, but I get an ORMEntityOutOfSyncException, and not the error you're running into...