Ale*_*dre 14 c# entity-framework transactionscope entity-framework-4.1
我需要在事务上下文中做这样的事情
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();
}
}
Run Code Online (Sandbox Code Playgroud)
我正在运行sql profiler但是看不到begin tran,那段代码是否正确?我错过了什么吗?
Ada*_*son 21
就像@Marc在评论中所说的那样,消息可能被过滤掉了.您只会在默认配置文件中获取T-SQL事务消息,而不是直接使用API发送的事务消息(如同TransactionScope
).
在SQL Server Profiler中,转到跟踪事件选择并选中"显示所有事件"复选框.在底部是一个"交易"类别,它应该给你你需要的东西.具体来说,事件以TM:
.
归档时间: |
|
查看次数: |
4725 次 |
最近记录: |