问题
I need to use a Transaction Scope with Entity Framework 4 and a Firebird database. I am using the FireBird Entity Framework provider.
My problem is that once SaveChanges has been called on an object, the data is persisted to the database, instead of when transactionScope.Complete() is called. This results in data never rolling back, even if an exception occurs inside the using (TransactionScope ...) block.
This seems to be a problem with the FireBird DB, I have tested the exact same code with MS SQL 2008 and RollBack works correctly.
What do I need to do to enable Rolling Back with FireBird?
using ( var context = new Model1Container() )
{
bool success = false;
using ( TransactionScope transactionScope = new TransactionScope() )
{
PERSON person = new PERSON();
person.NAME = "test";
context.AddToPERSON(person);
context.SaveChanges(SaveOptions.DetectChangesBeforeSave);
success = true;
//transactionScope.Complete(); If this line is not hit, Transaction should Roll Back, but it does not.
}
if ( success )
{
context.AcceptAllChanges();
}
}
回答1:
For firebird you need to explicitly say that it has to participate by adding Enlist=True in the connectionstring.
来源:https://stackoverflow.com/questions/6760812/firebird-and-entity-framework-transaction-rollback