可以从环境事务获得的SqlTransaction?事务、环境、SqlTransaction

2023-09-04 04:33:01 作者:活着就似最初

由于SQL Server的保存点功能( SqlTransaction.Save()),我想用 SqlTransactions 的一个非常有限的方式(我真的需要这个功能),同时仍然使用环境事务中的所有其他地方。我知道这意味着此code(和依赖性)现在是SQL Server特有的 - 这是好的。不过,我还是preFER跟随preferred环境事务中的所有其他地方的最佳做法的目的。 (如果我们需要迁移到Oracle或东西,那么我们就需要返工这部分我们code,但不想返工整个codeBase的。)

Due to SQL Server's SavePoints feature (SqlTransaction.Save()), I would like to use SqlTransactions in a very limited fashion (I REALLY need this functionality) while still using ambient transactions in all other places. I realize that this means that this code (and dependencies) are now SQL Server-specific - this is fine. However, I'd still prefer to follow the preferred ambient transactions in all other places for best practice purposes. (If we need to move to Oracle or something, then we'll need to rework this part of our code but don't want to rework the entire codebase.)

是否有可能得到一个电流的SqlTransaction Transaction.Current (返回类型的对象 System.Transactions.Transaction )或其他方式? (我可能是错的,但我猜,这是最终实现环境目标交易在运行时的对象)

Is it possible to get a current SqlTransaction from Transaction.Current (which returns an object of type System.Transactions.Transaction) or some other way? (I may be wrong but I am guessing that this is ultimately the object that implements ambient Transaction object at run-time)

(相关但不同的问题,我目前工作的,如果你在需要更多信息为什么)

推荐答案

据我所知,这根本无法做到的。既然我得到这个没有任何反应,我这标志着作为回答。我,还是会出错。我根本想不通这一个,但是,并没有足够的时间寻找到它的任何进一步。

As far as I can tell, this simply cannot be done. Given that I'm getting no response to this, I'm marking this as the answer. I could, still, be wrong. I simply cannot figure this one out, though, and don't have the time to look into it any further.