The ObjectMapper .NET Project

Official blog of the AdFactum ObjectMapper .NET

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);

 

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>