[英]EF Code First DBContext and Transactions
I would like know what is the best possible way to implement transactions with DBContext
. 我想知道用DBContext
实现事务的最佳方法是什么。 In particular, 特别是,
DbContext.SaveChanges
implement transaction internall if i change multiple entities? 如果我更改多个实体, DbContext.SaveChanges
是否实现了事务内部? DbContext.SaveChanges
multiple times(same contxet/different contxets), how transaction can be achieved? 如果我想多次调用DbContext.SaveChanges
(相同的contxet /不同的contxets),如何实现事务? SaveChanges
uses transaction internally. SaveChanges
内部使用事务。 TransactionScope
to wrap multiple calls to SaveChanges
使用TransactionScope
包含对SaveChanges
多个调用 Example: 例:
using(var scope = new TransactionScope(TransactionScopeOption.Required,
new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
{
// Do something
context.SaveChanges();
// Do something else
context.SaveChanges();
scope.Complete();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.