开发者

Firebird and Entity Framework Transaction Rollback

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();
            }
        }


For firebird you need to explicitly say that it has to participate by adding Enlist=True in the connectionstring.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜