0
在我們目前的項目已經發生了,我們有時窩創建一個DataContext和TransactionScope的是這樣的:Linq2Sql DataContext和TransactionScope嵌套錯誤?
using(var dc = OurDataContext.CreateInstance())
{
DoSomething(dc);
...
}
void DoSomething(OurDataContext dc)
{
using(var scope = new TransactionScope())
{
// DoSomethingElse() might call dc.SubmitChanges() which is why
// we inserted the TransactionScope here
DoSomethingElse(dc);
dc.SubmitChanges();
scope.Complete();
}
}
是否如我們期望它這真的管用嗎?
(儘管最後期限緊,這是相當尷尬的發現這樣的代碼。)