I have a code like this
try
{
MyModel model = repo.GetData();
if(model == null)
{
return model;
}
else
{
MyResponse response = checkData();
if(response)
{
return model;
}
UpdateData();
}
}
catch(Exception e)
{
....
}
return model;
I want to add TransactionScope like this.
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
And I wanna ask, is it okay if I have multiple return statement before code reach ts.Complete()? I can't set ts into null in finally block because TransactionScope is inside try block.