【发布时间】:2010-04-29 19:30:30
【问题描述】:
为了从不受脏数据影响的应用程序部分中选择数据,我创建了一个 TransactionScope,它根据 Hanselman here 的建议指定 ReadUncommitted IsolationLevel。
我的问题是,我是否仍然需要在 using 块的末尾执行 oTS.Complete() 调用,即使此事务范围不是为了在插入、更新期间桥接 2 个数据库之间的对象依赖关系而构建的,还是删除?
例如:
List<string> oStrings = null;
using (SomeDataContext oCtxt = new SomeDataContext (sConnStr))
using (TransactionScope oTS = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted }))
{
oStrings = oCtxt.EStrings.ToList();
oTS.Complete();
}
【问题讨论】:
-
来自msdn.microsoft.com/en-us/library/ms172152.aspx,“当 TransactionScope 对象加入现有的环境事务时,处置范围对象可能不会结束事务,除非范围中止事务。如果环境事务是由根范围,只有在根范围被释放时,才会在事务上调用 Commit。如果事务是手动创建的,则事务在它被中止或由其创建者提交时结束。”
标签: c# linq-to-sql transactions