Chili.Opf3 Send comments on this topic.
StartTransaction(IsolationLevel) Method
See Also  Example
Chili.Opf3 Namespace > ObjectContext Class > StartTransaction Method : StartTransaction(IsolationLevel) Method




level
Starts a new transaction.

Syntax

Visual Basic (Declaration) 
Overloads Public Function StartTransaction( _
   ByVal level As IsolationLevel _
) As Transaction
Visual Basic (Usage)Copy Code
Dim instance As ObjectContext
Dim level As IsolationLevel
Dim value As Transaction
 
value = instance.StartTransaction(level)
C# 
public Transaction StartTransaction( 
   IsolationLevel level
)
Managed Extensions for C++ 
public: Transaction* StartTransaction( 
   IsolationLevel level
) 
C++/CLI 
public:
Transaction^ StartTransaction( 
   IsolationLevel level
) 

Parameters

level

Return Value

Returns an object that inherits of the abstract Transaction class if the transaction has been started sucessfully. Null otherwise.

Example

The following example shows how to use transaction management.
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. 
  
// Get an ObjectSet containing all user matching the name. 
// The result is sorted by Name. 
ObjectSet<User> objectSet = context.GetObjectSet<User> 
    ("Name like {0} SortBy Name Asc", "%mith%"); 
  
// Change all names of the user objects. 
foreach(User user in objectSet) 

    user.Name = "new Name"; 

  
try 

    // Starts a new Transaction. 
    using(Transaction t = context.StartTransaction()) 
    { 
        // Deletes the user object from the storage. 
        context.PersistChanges(objectSet); 
  
        // Commit the changes to the storage. 
        t.Commit(); 
    } 

catch (Exception ex) 

    // Rolls the changes back. 
    context.Rollback(); 
    Console.WriteLine("Error: " + ex.Message"); 

    

Remarks

Starts a new transaction on the connected IStorage. This routine is only supported if the storage implements also the ITransactionStorage interface. You don't get an exception if the storage does not support transactions and you call this routine.

Requirements

Platforms: Windows 2000, Windows XP family, Windows Server 2003 family, Windows Vista family

See Also