在EF6,MVC,MySQL场景中,使用EF TransactionScope和DBContext.BeginTransaction有什么不同?TransactionScope中没有显式回滚。
应该是吗?
using transactionscope
{
using dbContext
{
.........
.........
dbContext.SaveChanges();
.............
.......
dbContext.SaveChanges();
}
transactionscope.Complete();
// there is no .Rollback method
}或
using dbContext
{
using dbtx = dbContext.Database.BeginTransaction
{
.........
.........
dbContext.SaveChanges();
.............
.......
dbContext.SaveChanges();
dbtx.Commit()
// and dbtx.Rollback() when exception occurs
}
}有什么关系?
发布于 2017-06-02 04:59:14
我不会注意其中的区别。我不会担心隔离级别。执行以下操作:全部回滚(不需要显式回滚)或全部提交:
using (TransactionScope scope = new TransactionScope())
{
...
db.SaveChanges();
...
db.SaveChanges();
scope.Complete();
}https://stackoverflow.com/questions/44234861
复制相似问题