TransactionScope,哪里是在sql profiler上开始事务? [英] TransactionScope, where is begin transaction on sql profiler?
问题描述
我需要在事务环境中做这样的事情
i need to do something like this on a transaction context
using(var context = new Ctx())
{
using (TransactionScope tran = new TransactionScope())
{
decimal debit = 10M;
int id = 1;
var data = context.Cashier
.Where(w => w.ID == id)
.Select(s => new{ s.Money })
.Single();
Cashier cashier = new Cashier(){ ID = id };
context.Cashier.Attach(cashier);
cashier.Money = data.Money - debit;
context.Entry(cashier).Property(p => p.Money ).IsModified = true;
context.SaveChanges(SaveOptions.None);
tran.Complete();
}
}
我正在运行sql profiler,但看不到开始tran,那块代码正确吗?我错过了什么?
I'm running sql profiler but can't see begin tran, is that block of code correct? Am I missing something?
推荐答案
像@Marc在他的评论中说,消息可能被过滤掉。您只会在默认配置文件中获取T-SQL事务消息,而不是直接使用API发送的事务消息(如 TransactionScope
)。
Like @Marc said in his comment, the messages are probably being filtered out. You would only be picking up T-SQL transaction messages in the default profile, not transaction messages that are sent using the API directly (as TransactionScope
does).
在SQL Server Profiler中,转到跟踪事件选择并选中显示所有事件复选框。底部是交易类别,它应该给你所需要的。具体来说,以 TM开头的事件:
。
In SQL Server Profiler, go to the trace event selection and check the "Show All Events" checkbox. Down at the bottom is a "Transactions" category, and it should give you what you need. Specifically, the events starting with TM:
.
这篇关于TransactionScope,哪里是在sql profiler上开始事务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!