-
Notifications
You must be signed in to change notification settings - Fork 55
Transactions
Long Le edited this page Sep 20, 2017
·
3 revisions
Built in transaction handling in UnitOfWork LinqPad Example
var productRepository = new Repository<Product>(this);
var product2 = await productRepository.FindAsync(7);
product2.Dump();
// Begin transaction
unitOfWork.BeginTransaction();
try
{
product2.ProductName = "Chai4";
product2.ObjectState = ObjectState.Modified; // always set the ObjectState
// <Do other transactions here>
productRepository.Update(product2);
var changes = await unitOfWork.SaveChangesAsync();
changes.Dump("changes");
// Commit Transaction
unitOfWork.Commit();
}
catch
{
// Rollback transaction
unitOfWork.Rollback();
}
product2 = await productRepository.FindAsync(7);
product2.Dump();
The Official URF Team | Docs: goo.gl/6zh9zp | Subscribe to URF Updates: @lelong37 | Blog: blog.longle.io