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();
}
}
I'm running sql profiler but can't see begin tran, is that block of code correct? Am I missing something?
BEGIN TRANSACTION (Transact-SQL)
Transaction Control The following are the commands used to control transactions: BEGIN TRANSACTION: It is a command that indicates the beginning of each transaction. COMMIT: It is a command used to save the changes permanently in the database.
In SQL Server Profiler 2008, when starting/configuring the trace, go to the "Events Selection" tab, click on the "Show all events" checkbox, and then in the list under the Stored Procedures section select the SP:StmtStarting and SP:StmtCompleted events to be included in the trace.
Definition: TransactionalScope makes your code block Transactional. You can easily maintain one transaction for multiple databases or a single database with multiple connectionstrings, using TransactionScope. When you use TransactionScope there is no need to close any Database connections in the middle.
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).
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:
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With