I'm working on a plugin that gets loaded via IOC from a 3rd party data driver. The plugin and data driver both operate on the same SQL Server 2005 database, but the plugin focuses on a small subset of tables that have foreign key relationships to the tables that the data driver manages.
My problem is that in some operations, the data driver is creating an SQLTransaction around calls to my plugin, which is causing my operations to fail (timeout exception). A typical scenario follows this path of pseudo-code / code:
DataDriver.InsertEntity(IBusinessObject businessObject)
{
CreateSqlTransaction();
AddEntityToEntityTable(businessObject);
Plugin.PersistAdditionalData(businessObject);
CommitOrRollbackTransaction();
}
In my plugin, I'm doing something like this:
Plugin.PersistAdditionalData(IBusinessObject businessObject)
{
var dbObject = GetObjectFromDatabase(businessObject); // Via Entity Framework
var additionalData = CreateAdditionalDataObject(businessObject);
// Insert data to a table with a foreign key relationship to a table that the
// data driver has just inserted the business object data to in the current
// transaction.
_entityModel.AddToObject_AdditionalData_AssociationSet(additionalData);
_entityModel.SaveChanges();
}
I've tried wrapping my method in a using(TransactionScope){...} block, but haven't been able to get that to work. It did move the failure from the read (GetObjectFromDatabase) to the save however.
I don't have access to the data driver code or to any notifications that the transaction has been committed or rolled back. It may be possible for me to get the developer to make some changes if I know what to suggest though, but I would prefer a solution that doesn't require that.