Devart如何使用数据库事务
找了很长时间都没找到,无奈翻墙去翻官博,终于找到了,有需要的小伙伴可以参考
//Opening connection
context.Connection.Open();
DEPT department = context.DEPT.Where(d => d.DEPTNO == 10).First();
department.LOC = “TEST”;
//Opening transaction
using (System.Data.Common.DbTransaction transaction
= context.Connection.BeginTransaction())
{
//This call participates in the transaction
context.SaveChanges();
department.DNAME = “TEST”;
//This call also participates in the transaction
context.SaveChanges();
//Replace the flag condition with the one you need
//or remove it and leave only commit part
if(flag)
{
//transaction completed successfully, both calls succeeded
transaction.Commit();
}
else
{
//something is wrong, both calls are rolled back
transaction.Rollback();
}
}
另附图片