Quantcast
Channel: URF - Unit of Work & (extensible/generic) Repositories Framework
Viewing all articles
Browse latest Browse all 1539

Updated Wiki: Transactions

$
0
0
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();

Viewing all articles
Browse latest Browse all 1539

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>