に私はこのようなTransactionScope
を追加するこの複数TransactionScope.Complete()を使用して
try
{
MyModel model = repo.GetData();
if(model == null)
{
return model;
}
else
{
MyResponse response = checkData();
if(response)
{
return model;
}
UpdateData();
}
}
catch(Exception e)
{
....
}
return model;
のようなコードを持っています。
try
{
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
{
MyModel model = repo.GetData();
if(model == null)
{
return model;
}
else
{
MyResponse response = checkData();
if(response)
{
return model;
}
UpdateData();
}
ts.Complete();
}
}
catch(Exception e)
{
....
}
return model
そして私は尋ねたい、それはコードがts.Complete()
に到達する前に、私は複数のreturn
文を持っている場合は大丈夫でしょうか? TransactionScope
がtryブロック内にあるので、finally
ブロックでts
をヌルに設定できません。