#region 事务
if (false)
{
//这种好像不行会报,"This platform does not support distributed transactions."
using (TransactionScope trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
try
{
await _lianCallContext.SaveChangesAsync();
await _lianCallManageContext.SaveChangesAsync();
trans.Complete();
}
catch (Exception ex)
{
Transaction.Current.Rollback();
return await Task.FromResult(resposeData.Error(ex.Message));
}
}
}
else
{
var tran_lianCall = _lianCallContext.Database.BeginTransaction();
try
{
await _lianCallContext.SaveChangesAsync();
//没问题就再创建另一个数据库事务
var tran_lianCallManage = _lianCallManageContext.Database.BeginTransaction();
try
{
await _lianCallManageContext.SaveChangesAsync();
await tran_lianCallManage.CommitAsync();
}
catch (Exception ex)
{
await tran_lianCallManage.RollbackAsync();
await tran_lianCall.RollbackAsync();
//return await Task.FromResult(resposeData.Error(ex.Message));
}
finally
{
await tran_lianCallManage.DisposeAsync();
}
await tran_lianCall.CommitAsync();
}
catch (Exception ex)
{
await tran_lianCall.RollbackAsync();
//return await Task.FromResult(resposeData.Error(ex.Message));
throw ex;
}
finally
{
await tran_lianCall.DisposeAsync();
}
}
#endregion