我有這樣多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;
我想補充TransactionScope
這樣的代碼。
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
我想問問,是不是好,如果我有多個return
語句代碼達到ts.Complete()
過嗎?因爲TransactionScope
位於try塊內,所以我不能在finally
塊中將ts
設置爲null。