Exception: NoOpenTransactionException
Posted by Gerhard Stephan on April 17th, 2008
The NoOpenTransactionException will always be thrown if a Save-Method is called without opening a Transaction first.
[Test]
[ExpectedException(typeof(NoOpenTransactionException))]
public void TestNoOpenTransactionException()
{
Buying buying = new Buying(5, "Hotdogs");
using (AdFactum.Data.ObjectMapper mapper = OBM.CreateMapper(Connection))
{
// A NoOpenTransactionException will be thrown, because no transaction has been opened.
mapper.Save(buying);
}
}
To prevent this exception you have to call the BeginTransaction Method. It’s recommended to use the BeginTransaction of the OBM Helper class in order to handle nested transactions.
nested = OBM.BeginTransaction(mapper);
mapper.Save(buying);
OBM.Commit(mapper, nested);
