I think you're right in thinking that your code should not be committed to
the database.

This is how I handle transactions in my app as well.

Another thing to note is that if you don't Commit, the Dispose (closing of
using) will auto-rollback. This is unadvised, but just fyi.

Do you have NHProfiler running? If not, I would suggest using it to
hopefully get a better understanding of what's going on.

------
Joe Brockhaus
joe.brockh...@gmail.com
------------


On Wed, Nov 9, 2011 at 7:22 PM, The Last Ottoman
<ottomanthel...@gmail.com>wrote:

> Hi all,
>
> I used unit-of-work pattern all around the project I am working on, and I
> thought it worked properly.
>
> Then I got an exception, and saw data committed to DB.
>
> Here is my code:
>
>
> //////////////////////////////////////////////////////////////////////////////
>
>             using (ITransaction tx = session.BeginTransaction())
>             {
>                 try
>                 {
>                     City city = new City()
>                     {
>                         Name = "Istanbul"
>                     };
>                     session.Save(city);
>
>                     city = new City()
>                     {
>                         Name = "Ankara"
>                     };
>                     session.Save(city);
>
>                     city = new City()
>                     {
>                         Name = "Konya"
>                     };
>                     session.Save(city);
>
>                     Industry industry = new Industry()
>                     {
>                         Name = "Custom Software"
>                     };
>                     sector.Industries.Add(industry); // Here where
> exception occurs
>                     tx.Commit();
>                 }
>                 catch(Exception ex)
>                 {
>                     tx.Rollback();
>                 }
>              }
>
>  /////////////////////////////////////////////////////////////////
>
> As normal, I assumed since tx.Rollback() is called after an exception is
> caught, no data should be written to database.
> But I realized that all data saved before exception occured has been
> successfully written to DB.
>
> What am i missing with Transaction structure? Should I put a specific
> directive to make it work, or am I using it completely wrong?
>
> Thanks in advance,
> Sadullah
>
> --
> You received this message because you are subscribed to the Google Groups
> "Fluent NHibernate" group.
> To post to this group, send email to fluent-nhibernate@googlegroups.com.
> To unsubscribe from this group, send email to
> fluent-nhibernate+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/fluent-nhibernate?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply via email to