Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transactions in C#

In addition to this question: Preorder tree traversal copy folder I was wondering if it is possible to create a transaction that contains different calls to the database.

ex:

public bool CopyNode(int nodeId, int parentNode)
    { 
        // Begin transaction.
        try
        {
            Method1(nodeId);
            Method2(nodeId, parentNode);
            Method3(nodeId);
        }
        catch (System.Exception ex)
        { 
            //rollback all the methods
        }
    }

I don't know if this is possible. We are using subsonic to do the database calls. This is really important, not only for the tree traversal problem but also for some other stuff we do.

The main idea is that we can't let our dabase get corrupted with uncomplete data.

like image 705
user29964 Avatar asked Feb 23 '09 12:02

user29964


1 Answers

That is possible, you can find a example here

Or perhaps a transaction scope...

http://msdn.microsoft.com/en-us/library/ms172152.aspx

like image 88
Bruno Costa Avatar answered Oct 03 '22 14:10

Bruno Costa