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)
|
| Managed Extensions for C++ | |
|---|
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
Requirements
Platforms: Windows 2000, Windows XP family, Windows Server 2003 family, Windows Vista family
See Also