Mh, I haven't tried it but one thing is probably wrong: OnDispose.Commit
So Save() throws an exception which causes it to leave the using block and in turn tries to commit the transaction with an invalid object. That doesn't seem right. You should use OnDispose.Rollback and explicitly commit at the end when all actions where successful.

Morten Brix Pedersen wrote:
I'm having an issue where my transactions are not being properly
rolled back when an exception occurs. I would really appreciate any
insight to this problem.

My entity is defined as follows:

        [ActiveRecord]
        public class Dog : ActiveRecordLinqBase<Dog>
        {
                [PrimaryKey]
                public Guid Id
                {
                        get;
                        set;
                }

                [Property(Length = 5)]
                public string Name
                {
                        get;
                        set;
                }
        }

The following code correctly throws an exception when I insert a dog
with a name that is too long. However, future queries on the entity
gives me an exception. Note that if I change the primary key to be of
integer type instead of Guid, it works!

                using (new SessionScope())
                {
                        try
                        {
                                using (new TransactionScope(TransactionMode.New,
OnDispose.Commit))
                                {
                                        var dog = new Dog
                                        {
                                                Name = "TooLongNameForADog"
                                        };
                                        dog.Save();
                                }

                        }
                        catch (Exception ex)
                        {
                                // Exception occurs: "An error occured when 
trying to dispose the
transaction: Could not insert [...]"
                                var dogFromDatabase = Dog.FindFirst();
                                // A new exception gets thrown: "Could not 
perform SlicedFindAll
for Dog: "could not insert [...]"
                        }
                }

Thanks.



--
You received this message because you are subscribed to the Google Groups "Castle 
Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to