Chapter 6. Transactions


WF aligns with the programming model for transactions that is provided by the System.Transactions namespace in the .NET Framework. There is plenty of documentation and additional explanatory material that has been written about this APIand we encourage you to familiarize yourself with the specificsbut the bottom line is that System.Transactions presents a simplified model for using transactions such that the nuts and bolts of managing a transaction (e.g., the selection of transaction managers, enlistment of resources, and transaction promotion) are, unless you need to get to them, agreeably out of sight.

Thus in C#, you just write the following:

 using (TransactionScope ts = new TransactionScope()) {   // use transactional resources...   ts.Complete(); } 


The use of a System.Transactions.TransactionScope object demarcates a block of C# code that participates in a transaction. Your code does not explicitly create an actual transaction object; that is taken care of for you by the transactionScope.

Furthermore, resource managers that are compatible with System.Transactions will, when utilized within a TRansactionScope, automatically detect the presence of what is known as the ambient transaction and enlist themselves appropriately. SQL Server is one example of such a resource manager. Thus, transactional programming against a database is as simple as this:

 using (TransactionScope ts = new TransactionScope()) {   using (System.Data.SqlClient.SqlConnection conn =     new System.Data.SqlClient.SqlConnection(...))   {     ...   }   ts.Complete(); } 





Essential Windows Workflow Foundation
Essential Windows Workflow Foundation
ISBN: 0321399838
EAN: 2147483647
Year: 2006
Pages: 97

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net