I am just wondering what a good reason to use Serializable as the default Isolationlevel may be when creating a System.Transactions TransactionScope
A useful way to cut down writing boilerplate code is to wrap it in a builder class like so:
public static class TransactionScopeBuilder
{
///
/// Creates a transactionscope with ReadCommitted Isolation, the same level as sql server
///
/// A transaction scope
public static TransactionScope CreateReadCommitted()
{
var options = new TransactionOptions
{
IsolationLevel = IsolationLevel.ReadCommitted,
Timeout = TransactionManager.DefaultTimeout
};
return new TransactionScope(TransactionScopeOption.Required, options);
}
}
Then you can use it like this when creating a transaction scope:
using (var scope = TransactionScopeBuilder.CreateReadCommitted())
{
//do work here
}
You can add other common transaction scope defaults to the builder class as you need them.