Alternative to Save point when using System.Transactions

一世执手 提交于 2019-12-20 01:37:07

问题


How can I use classes from System.Transactions namespace to achieve similar effect as I can get when using SqlTransaction.Save(savePoint) and SqlTransaction.Rollback(savePoint). The effect of using these two methods is ability to create named save point in the running transaction and in case of issue rollback only to the save point (operations created before save point are not rolled back).


回答1:


Save Points are database specific in part of their implementation. Oracle implements them, and apparently so does SQL server.

System.Transactions is designed for full-bore transactions, and not intermediate save points along the way of a transaction.

Alas, because it would be nice to have this feature in the lowest-common denominator database supported: ACCESS JET.




回答2:


yourcontext.Database.ExecuteSqlCommand(string.Concat("save transaction ", savePoint));

yourcontext.Database.ExecuteSqlCommand(string.Concat("rollback transaction ", savePoint));



来源:https://stackoverflow.com/questions/5412635/alternative-to-save-point-when-using-system-transactions

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