Firebird and Entity Framework Transaction Rollback

心不动则不痛 提交于 2019-12-25 03:46:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!