通过 SubSonic 3 在事务中修改 SQLite 数据库架构和数据
我正在使用 Visual Studio 2008、C#、SQLite(通过 System.Data.SQLite 和 SubSonic 3)。我的应用程序已达到需要升级数据库架构(添加列、触发器等)然后通过 SubSonic 添加新记录的状态生成的 ActiveRecord 对象 - 全部都在单个事务的范围内,以便可以很好地回滚任何故障。
理想情况下,这就是我希望做的事情:
Begin Transaction
try
Update Schema to latest version
Use SubSonic objects to add new records/modify existing
Commit Transaction
catch
Rollback Transaction
不幸的是,这不起作用。目前所有架构更改都是通过 SubSonic.Query.CodingHorror 进行的,它似乎不尊重事务。有没有办法在单个事务范围内执行架构更改和 SubSonic 数据更改?
I'm using Visual Studio 2008, C#, SQLite via System.Data.SQLite with SubSonic 3. My application has gotten to a state where I need to upgrade the database schema (add columns, triggers, etc) then add new records via SubSonic generated ActiveRecord objects - all within the scope of a single transaction so that any failures could be nicely rolled back.
Ideally, this is sort of what I was hoping to do:
Begin Transaction
try
Update Schema to latest version
Use SubSonic objects to add new records/modify existing
Commit Transaction
catch
Rollback Transaction
Unfortunately, this doesn't work. All the schema changes are currently being via SubSonic.Query.CodingHorror, which doesn't seem to respect transactions. Is there a way to perform both schema changes and SubSonic data changes within the scope of a single transaction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我找到了问题的答案:对所有操作使用相同的数据库连接,并在该一个数据库连接上使用事务。由于我没有告诉 SubSonic 如何为我处理所有数据库连接 - 它使用默认方法,每个查找或创建的对象或 CodingHorror 一个连接。由于事务不能跨越数据库连接,所以我看到的行为完全是预料之中的。
一旦我创建了自己的数据库连接并对其进行了查找、创建和 CodingHorror 模式更改,所有事务内容就开始正常工作。
I think I found the answer to my question: use the same database connection for all actions and use transaction on that one database connection. Since I hadn't told SubSonic how to handle all the database connections for me - it used the default method, one connection per lookup or created object or CodingHorror. Since transactions can't span database connections, the behavior I saw was fully expected.
Once I created my own database connection and did the lookups, creates and CodingHorror schema changes on it, all transaction stuff begin to work properly.