<p>I decided to make a system for a client using <a href="https://web.archive.org/web/20080517021542/http://www.castleproject.org/activerecord/index.html" rel="nofollow noreferrer">Castle ActiveRecord</a>, everything went well until I found that the transactions do not work, for instance;</p>

<pre><code>               TransactionScope t = new TransactionScope();

               try
               {
                   member.Save();

                   //This is just to see transaction working
                   throw new Exception("Exception");  

                   foreach (qfh.Beneficiary b1 in l)
                   {
                       b1.Create();
                   }


               }
               catch (Exception ex)
               {

                   t.VoteRollBack();
                   MessageBox.Show(ex.Message);
               }
               finally
               {
                   t.Dispose();
               }
</code></pre>

<p>But it doesn't work, I throw an Exception just to try the transaction rolls back, but for my surprise I see that the first [Save] records into the database. What is happening?</p>

<p>I'm new on Castle and NHibernate, firstly I saw it very attractive and I decided to go on with it and MySQL (I've never worked with this DB), I tried ActiveWriter and it seemed very promising but after a long and effortly week I see this issue and now I feel like I'm stuck and like I've wasted my time. It is supposed to be easy but right now I'm feeling a frustated cause I cannot find enough information to make this workout, can you help me?</p>

[{'answer_id': 38737, 'author': 'Michael Haren', 'author_id': 29, 'author_profile': 'https://Stackoverflow.com/users/29', 'pm_score': 3, 'selected': True, 'text': '<p>Ben\'s got it. That doc is a little confusing. Refer to the last block <a href="https://web.archive.org/web/20080417014143/http://www.castleproject.org/ActiveRecord/documentation/v1rc1/usersguide/scopes.html" rel="nofollow noreferrer">on the page</a>, "Nested transactions". </p>\n'}, {'answer_id': 38740, 'author': 'Ben Scheirman', 'author_id': 3381, 'author_profile': 'https://Stackoverflow.com/users/3381', 'pm_score': 3, 'selected': False, 'text': '<p>You need to wrap the code in a session scope, like this:</p>\n\n<pre><code>using(new SessionScope())\n{\n   a.Save();\n   b.Save();\n   c.Save();\n}\n</code></pre>\n\n<p>Read more <a href="https://web.archive.org/web/20080417014143/http://www.castleproject.org:80/activerecord/documentation/v1rc1/usersguide/scopes.html" rel="nofollow noreferrer">here</a>.</p>\n'}, {'answer_id': 38747, 'author': 'Nelson Miranda', 'author_id': 1130097, 'author_profile': 'https://Stackoverflow.com/users/1130097', 'pm_score': 0, 'selected': False, 'text': "<p>I finally fixed, it happened that I was doing wrong, I overrode the Save method of the Member class and made sessionScope inside and inside of it a transaction scope, so when a involved all of that in a transaction scope it saved in the database, so when I threw the exception everything was already saved, I think that's it.</p>\n\n<p>All in all, thanks for the help.</p>\n"}]
['https://Stackoverflow.com/questions/38729', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1130097/']