替代品的SqlTransaction公开活动 - C#? [英] Alternate to SqlTransaction exposing Events - C#?

查看:184
本文介绍了替代品的SqlTransaction公开活动 - C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行一些日志记录时的SqlTransaction提交或rolledback。我看到的SqlTransaction类没有公开任何这样的事件,如OnCommit或OnRollback。

I want to perform some logging when a SqlTransaction is committed or rolledback. I see that SqlTransaction class does not expose any such events like OnCommit or OnRollback.

该死的!的SqlTransaction类是密封的,我不能帮助它与继承。

damn! SqlTransaction class is sealed, I cant help it out with inheritance.

现在,什么才是真正的原因,他们没有让这些事件发生?

Now, what must be the reason they have not allowed these events to happen ?

有没有办法做到这些事件的SqlTransaction或的SqlTransaction任何这样的替代提供?

Is there a way to do these events with SqlTransaction or any such alternate of SqlTransaction that provides ?

感谢。

推荐答案

一种可能性是创建一个实现IDbTransaction一类,包装内部的SqlTransaction。这样,你会不得不说是这样的:

One possibility is to create a class that implements IDbTransaction, and wraps an internal SqlTransaction. You would then have to say something like:

IDbCommand icommand = (IDbCommand)command; // Where command is a SqlCommand.
command.Transaction = itransaction; // Class implementing IDbTransaction and wrapping SqlTransaction.

我的没有的尝试这样做,上面必须考虑伪code。我很怀疑它甚至会工作,但它可能是值得一试。

I have not tried this and the above must be considered pseudocode. I'm skeptical it will even work, but it's probably worth a try.

这篇关于替代品的SqlTransaction公开活动 - C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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