This website is intended as archive for old content and forums.
Please visit http://opf3.codeplex.com for the project's new website.

Announcements

FORUM TOPIC

This forum is used by the Opf3 developers to announce new features or to discuss with you about ideas on new features.

RSS
Christian Liensberger [Moderator]
Posted on the 06/26/06 1:00 PM
Transaction
Reply Quote
 Version 3.0.9.x introduces a new class with name "Transaction". This clas is returned by the ObjectContext when calling StartTransaction (if the ObjectContext was able to start a transaction on the storage, otherwise null).

The Transaction class implements the IDisposable interface, which allows you to use the C# or VB.NET "using" statement:

User u2 = new User();
u2.IsAdministrator = true;
u2.LastLogin = DateTime.Now;
u2.Username = "Foo";

try
{
    // Putting the start of the transaction in a using statement
    // makes sure that the transaction is automatically rolled
    // back if not committed (when leaving the using block).
    using (Transaction t = context.StartTransaction())
    {
        // Try to save the user.
        context.PersistChanges(u2);

        // Commit the transaction here. The object was saved
        // properly (no exception thrown).
        t.Commit();
    }
}
catch (StorageException ex)
{
    // We got an exception (the transaction is already
    // rolled back at this stage) and show it to the user.
    Console.WriteLine("Error during save" + ex.Message);
}



This new class makes the code easier to read and avoids problems with forgetting to roll back a transaction.

Regards,
Christian

Andrzej Śliwa
Posted on the 07/01/06 4:02 PM
RE: Transaction
Reply Quote
 Ok cool future .. but old syntax work with new ??
When new version opf3 come to us ?? :D

GOOD WORK Christian

Christian Liensberger [Moderator]
Posted on the 07/01/06 6:32 PM
RE: Transaction
Reply Quote
 Hi,

both versions work. Although I'm thinking to mark the old commit and rollback as obsolete. What does everybody else think? Should they stay or be marked as obsolete?

Marv
Posted on the 09/13/06 12:59 PM
RE: Transaction
Reply Quote
 Hello,

Just wondering what would be the best practice to handle transaction using Opf3 if the application needs to deal with multiple storages?

Have you tested Opf3 with .NET 2.0 System.Transactions? We have a 3rd party application which we do not have direct access to the SQL server, instead, we will need to call its APIs to make changes to the data. I'm thinking of using .NET 2.0 System Transactions, but havn't had the time to test it yet.

Thanks

Marvin

Christian Liensberger [Moderator]
Posted on the 09/15/06 10:09 AM
RE: Transaction
Reply Quote
 Hi Marv,

Opf3 isn't tested with them. We had not time so far to test them with .NET 2.0 Transactions.

Regards,
Christian

All times are in GMT.