Knight Data Access Layer
Transactions VB.NET
Basic Tasks VB.NET > Saving Data > Transactions VB.NET

Transactions are handled as expected through ADO.NET.  Begin, Commit, and Rollback are supported.  Below is an example of a transaction.  The Unit of Work pattern is also supported.  See the Patterns section.

 

'Get the current instance of the helper

Dim db As IDataHelper = DataHelper.SessionFactory()

 

'Begin a transaction to save two people at once

db.BeginTransaction()

 

'Create a new Person to save to the database

Dim person1 As New Person()

person1.FirstName = "John"

person1.LastName = "Smith"

 

'Save it to the database (see the SQL in the console)

db.Save(person1)

 

'Create another new Person to save to the database

Dim person2 As New Person()

person2.FirstName = "Jane"

person2.LastName = "Smith"

 

'Save it to the database (see the SQL in the console)

db.Save(person2)

 

'Get the current transaction and print out some info

Console.WriteLine(db.Transaction.Connection.ConnectionString)

 

'Commit the transaction

db.CommitTransaction()