What is the best practice for processing a batched series of CRUD operations in a single transaction with the Enterprise Library Data Access Block that it won't be esclated to a distributed transaction?
Edit Full Source:
public void BatchInsertEvents(IList<EventItem> events)
{
_dataAccessBase = new DataAccessBase("[dbo].[EventInsert]");
int count = 0;
try
{
using (var scope =
new TransactionScope(TransactionScopeOption.RequiresNew))
{
foreach (var eventItem in events)
{
_dataAccessBase.ClearParameters();
_dataAccessBase.AddInParameter("@time",
DbType.String, eventItem.Time);
...more params
_dataAccessBase.ExecuteNonQuery();
count++;
}
scope.Complete();
}
}
My DataAccessBase is just a wrapper class for the Database object
public class DataAccessBase
{
private readonly DbCommand _command;
private readonly Database _database;
public DataAccessBase(string storedProcName) : this(null, storedProcName)
{
}
public DataAccessBase(string connectionString, string storedProcName)
{
_database = string.IsNullOrEmpty(connectionString) ?
DatabaseFactory.CreateDatabase() :
DatabaseFactory.CreateDatabase(connectionString);
_command = _database.GetStoredProcCommand(storedProcName);
}
public void AddInParameter<T>(string parameterName,
DbType parameterType, T value)
{
_database.AddInParameter(_command,
parameterName, parameterType, value);
}
public void AddOutParameter<T>(string parameterName,
DbType parameterType, int parameterLength)
{
_database.AddOutParameter(_command,
parameterName, parameterType, parameterLength);
}
public void ClearParameters()
{
_command.Parameters.Clear();
}
public void ExecuteNonQuery()
{
_database.ExecuteNonQuery(_command);
}
}