use*_*491 50 entity-framework transactions entity-framework-4.1 dbcontext
我想知道实现事务的最佳方式是什么DBContext
.特别是,
DbContext.SaveChanges
如果我更改多个实体,是否实现事务内部?DbContext.SaveChanges
多次呼叫(相同的contxet /不同的contxets),如何实现交易?Lad*_*nka 72
SaveChanges
在内部使用交易.TransactionScope
换到多个呼叫SaveChanges
例:
using(var scope = new TransactionScope(TransactionScopeOption.Required,
new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
{
// Do something
context.SaveChanges();
// Do something else
context.SaveChanges();
scope.Complete();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
24652 次 |
最近记录: |