Knight Data Access Layer
Unit of Work Pattern
Basic Tasks C# > Patterns > Unit of Work Pattern

The unit of work pattern wraps a set of database operations in a transaction. 

 

//Get the current instance of the helper

IDataHelper db = DataHelper.SessionFactory();

 

using (new UnitOfWork(db))

{

db.ExecuteNonQuery("INSERT INTO Customers (FirstName,LastName) VALUES ('John','Smith')");

db.ExecuteNonQuery("INSERT INTO Customers (FirstName,LastName) VALUES ('John','Doe')");

}