Firebird和实体框架事务回滚 [英] Firebird and Entity Framework Transaction Rollback

查看:130
本文介绍了Firebird和实体框架事务回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Entity Framework 4和Firebird数据库中使用事务作用域。我正在使用FireBird实体框架提供程序。

I need to use a Transaction Scope with Entity Framework 4 and a Firebird database. I am using the FireBird Entity Framework provider.

我的问题是,一旦在对象上调用了SaveChanges,数据就会保存到数据库中,而不是在调用transactionScope.Complete()时。即使在using(TransactionScope ...)块内发生异常,这也会导致数据永不回滚。

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.

这似乎是FireBird DB的问题,我已经使用MS SQL 2008测试了完全相同的代码,并且RollBack可以正常工作。

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.

我需要做什么才能启用FireBird回滚?

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


推荐答案

firebird,您需要通过在连接字符串中添加Enlist = True来明确表示必须参与。

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

这篇关于Firebird和实体框架事务回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆