Chili.Opf3 Send comments on this topic.
Transaction Class
See Also  Members   Example 
Chili.Opf3.Storages Namespace : Transaction Class




Class that provides a generic transaction object. It is created by a class that implements ITransactionStorage.

Syntax

Visual Basic (Declaration) 
Public MustInherit Class Transaction 
Visual Basic (Usage)Copy Code
Dim instance As Transaction
C# 
public abstract class Transaction 
Managed Extensions for C++ 
public __gc abstract class Transaction 
C++/CLI 
public ref class Transaction abstract 

Example

The following example shows how to work with Transaction.
C#Copy Code
// Creates a new ObjectContext that uses an MsSql Server as storage. 
ObjectContext context = new ObjectContext(new MsSqlStorage("sa", "",  
    "localhost", "application")); 
 
// Other code... 
 
try 
                { 
    // Starts a transaction on the context. 
    // The using statement can be used here, because Transaction implements  
    // the IDisposable interface. 
    using(Transaction t = context.StartTransaction()) 
    { 
        // Tries to save an object. 
                        context.PersistChanges(user); 
        // The save was successful, let's commit now. 
                        t.Commit(); 
    } 
                } 
                catch (StorageException ex) 
                { 
    // We got an exception. Just print the message. 
                    Console.WriteLine("An exception happened."); 
                }

Remarks

This class provides a transaction object that is created by transactional storages. Those are storages that implement the ITransactionStorage interface.

Transaction inherits the IDisposable interface. That is done to automatically roll back a transaction if not committed.

The class provides methods to roll back or commit a transaction. It is recommended to use those methods instaead of the one provides by the ObjectContext to rollback or commit a transaction.

Inheritance Hierarchy

System.Object
   Chili.Opf3.Storages.Transaction
      Chili.Opf3.Storages.SqlTransactionBase

Requirements

Namespace: Chili.Opf3.Storages

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: Chili.Opf3 (in Chili.Opf3.dll)

See Also